##// END OF EJS Templates
Python 2to3, Spectra (all operations) working
George Yong -
r1167:1f521b07c958
parent child
Show More

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

@@ -1,7 +1,7
1 '''
1 '''
2 Created on Feb 7, 2012
2 Created on Jul 3, 2018
3
3
4 @author $Author$
4 @author $Author$
5 @version $Id$
5 @version $Id$
6 '''
6 '''
7 __version__ = '2.3'
7 __version__ = '3.0'
@@ -1,503 +1,503
1 """
1 """
2 The admin module contains all administrative classes relating to the schain python api.
2 The admin module contains all administrative classes relating to the schain python api.
3
3
4 The main role of this module is to send some reports. It contains a
4 The main role of this module is to send some reports. It contains a
5 notification class and a standard error handing class.
5 notification class and a standard error handing class.
6
6
7 $Id: admin.py 3966 2015-12-01 14:32:29Z miguel.urco $
7 $Id: admin.py 3966 2015-12-01 14:32:29Z miguel.urco $
8 """
8 """
9 import os
9 import os
10 import sys
10 import sys
11 import time
11 import time
12 import traceback
12 import traceback
13 import smtplib
13 import smtplib
14 import ConfigParser
14 import configparser
15 import StringIO
15 import io
16 from threading import Thread
16 from threading import Thread
17 from multiprocessing import Process
17 from multiprocessing import Process
18 from email.mime.text import MIMEText
18 from email.mime.text import MIMEText
19 from email.mime.application import MIMEApplication
19 from email.mime.application import MIMEApplication
20 from email.mime.multipart import MIMEMultipart
20 from email.mime.multipart import MIMEMultipart
21
21
22 import schainpy
22 import schainpy
23 from schainpy.utils import log
23 from schainpy.utils import log
24 from schainpy.model.graphics.jroplot_data import popup
24 from schainpy.model.graphics.jroplot_data import popup
25
25
26 def get_path():
26 def get_path():
27 '''
27 '''
28 Return schainpy path
28 Return schainpy path
29 '''
29 '''
30
30
31 try:
31 try:
32 root = __file__
32 root = __file__
33 if os.path.islink(root):
33 if os.path.islink(root):
34 root = os.path.realpath(root)
34 root = os.path.realpath(root)
35
35
36 return os.path.dirname(os.path.abspath(root))
36 return os.path.dirname(os.path.abspath(root))
37 except:
37 except:
38 log.error('I am sorry, but something is wrong... __file__ not found')
38 log.error('I am sorry, but something is wrong... __file__ not found')
39
39
40 class Alarm(Process):
40 class Alarm(Process):
41 '''
41 '''
42 modes:
42 modes:
43 0 - All
43 0 - All
44 1 - Send email
44 1 - Send email
45 2 - Popup message
45 2 - Popup message
46 3 - Sound alarm
46 3 - Sound alarm
47 4 - Send to alarm system TODO
47 4 - Send to alarm system TODO
48 '''
48 '''
49
49
50 def __init__(self, modes=[], **kwargs):
50 def __init__(self, modes=[], **kwargs):
51 Process.__init__(self)
51 Process.__init__(self)
52 self.modes = modes
52 self.modes = modes
53 self.kwargs = kwargs
53 self.kwargs = kwargs
54
54
55 @staticmethod
55 @staticmethod
56 def play_sound():
56 def play_sound():
57 sound = os.path.join(get_path(), 'alarm1.oga')
57 sound = os.path.join(get_path(), 'alarm1.oga')
58 if os.path.exists(sound):
58 if os.path.exists(sound):
59 for __ in range(2):
59 for __ in range(2):
60 os.system('paplay {}'.format(sound))
60 os.system('paplay {}'.format(sound))
61 time.sleep(0.5)
61 time.sleep(0.5)
62 else:
62 else:
63 log.warning('Unable to play alarm, sound file not found', 'ADMIN')
63 log.warning('Unable to play alarm, sound file not found', 'ADMIN')
64
64
65 @staticmethod
65 @staticmethod
66 def send_email(**kwargs):
66 def send_email(**kwargs):
67 notifier = SchainNotify()
67 notifier = SchainNotify()
68 print kwargs
68 print(kwargs)
69 notifier.notify(**kwargs)
69 notifier.notify(**kwargs)
70
70
71 @staticmethod
71 @staticmethod
72 def show_popup(message):
72 def show_popup(message):
73 if isinstance(message, list):
73 if isinstance(message, list):
74 message = message[-1]
74 message = message[-1]
75 popup(message)
75 popup(message)
76
76
77 @staticmethod
77 @staticmethod
78 def send_alarm():
78 def send_alarm():
79 pass
79 pass
80
80
81 @staticmethod
81 @staticmethod
82 def get_kwargs(kwargs, keys):
82 def get_kwargs(kwargs, keys):
83 ret = {}
83 ret = {}
84 for key in keys:
84 for key in keys:
85 ret[key] = kwargs[key]
85 ret[key] = kwargs[key]
86 return ret
86 return ret
87
87
88 def run(self):
88 def run(self):
89 tasks = {
89 tasks = {
90 1 : self.send_email,
90 1 : self.send_email,
91 2 : self.show_popup,
91 2 : self.show_popup,
92 3 : self.play_sound,
92 3 : self.play_sound,
93 4 : self.send_alarm,
93 4 : self.send_alarm,
94 }
94 }
95
95
96 tasks_args = {
96 tasks_args = {
97 1: ['email', 'message', 'subject', 'subtitle', 'filename'],
97 1: ['email', 'message', 'subject', 'subtitle', 'filename'],
98 2: ['message'],
98 2: ['message'],
99 3: [],
99 3: [],
100 4: [],
100 4: [],
101 }
101 }
102 procs = []
102 procs = []
103 for mode in self.modes:
103 for mode in self.modes:
104 if 0 in self.modes:
104 if 0 in self.modes:
105 for x in tasks:
105 for x in tasks:
106 t = Thread(target=tasks[x], kwargs=self.get_kwargs(self.kwargs, tasks_args[x]))
106 t = Thread(target=tasks[x], kwargs=self.get_kwargs(self.kwargs, tasks_args[x]))
107 t.start()
107 t.start()
108 procs.append(t)
108 procs.append(t)
109 break
109 break
110 else:
110 else:
111 t = Thread(target=tasks[mode], kwargs=self.get_kwargs(self.kwargs, tasks_args[mode]))
111 t = Thread(target=tasks[mode], kwargs=self.get_kwargs(self.kwargs, tasks_args[mode]))
112 t.start()
112 t.start()
113 procs.append(t)
113 procs.append(t)
114 for t in procs:
114 for t in procs:
115 t.join()
115 t.join()
116
116
117
117
118 class SchainConfigure():
118 class SchainConfigure():
119
119
120 __DEFAULT_ADMINISTRATOR_EMAIL = "juan.espinoza@jro.igp.gob.pe"
120 __DEFAULT_ADMINISTRATOR_EMAIL = "juan.espinoza@jro.igp.gob.pe"
121 __DEFAULT_EMAIL_SERVER = "jro-zimbra.igp.gob.pe"
121 __DEFAULT_EMAIL_SERVER = "jro-zimbra.igp.gob.pe"
122 __DEFAULT_SENDER_EMAIL = "notifier-schain@jro.igp.gob.pe"
122 __DEFAULT_SENDER_EMAIL = "notifier-schain@jro.igp.gob.pe"
123 __DEFAULT_SENDER_PASS = ""
123 __DEFAULT_SENDER_PASS = ""
124
124
125 __SCHAIN_ADMINISTRATOR_EMAIL = "CONTACT"
125 __SCHAIN_ADMINISTRATOR_EMAIL = "CONTACT"
126 __SCHAIN_EMAIL_SERVER = "MAILSERVER"
126 __SCHAIN_EMAIL_SERVER = "MAILSERVER"
127 __SCHAIN_SENDER_EMAIL = "MAILSERVER_ACCOUNT"
127 __SCHAIN_SENDER_EMAIL = "MAILSERVER_ACCOUNT"
128 __SCHAIN_SENDER_PASS = "MAILSERVER_PASSWORD"
128 __SCHAIN_SENDER_PASS = "MAILSERVER_PASSWORD"
129
129
130 def __init__(self, initFile = None):
130 def __init__(self, initFile = None):
131
131
132 # Set configuration file
132 # Set configuration file
133 if (initFile == None):
133 if (initFile == None):
134 self.__confFilePath = "/etc/schain.conf"
134 self.__confFilePath = "/etc/schain.conf"
135 else:
135 else:
136 self.__confFilePath = initFile
136 self.__confFilePath = initFile
137
137
138 # open configuration file
138 # open configuration file
139 try:
139 try:
140 self.__confFile = open(self.__confFilePath, "r")
140 self.__confFile = open(self.__confFilePath, "r")
141 except IOError:
141 except IOError:
142 # can't read from file - use all hard-coded values
142 # can't read from file - use all hard-coded values
143 self.__initFromHardCode()
143 self.__initFromHardCode()
144 return
144 return
145
145
146 # create Parser using standard module ConfigParser
146 # create Parser using standard module ConfigParser
147 self.__parser = ConfigParser.ConfigParser()
147 self.__parser = configparser.ConfigParser()
148
148
149 # read conf file into a StringIO with "[madrigal]\n" section heading prepended
149 # read conf file into a StringIO with "[madrigal]\n" section heading prepended
150 strConfFile = StringIO.StringIO("[schain]\n" + self.__confFile.read())
150 strConfFile = io.StringIO("[schain]\n" + self.__confFile.read())
151
151
152 # parse StringIO configuration file
152 # parse StringIO configuration file
153 self.__parser.readfp(strConfFile)
153 self.__parser.readfp(strConfFile)
154
154
155 # read information from configuration file
155 # read information from configuration file
156 self.__readConfFile()
156 self.__readConfFile()
157
157
158 # close conf file
158 # close conf file
159 self.__confFile.close()
159 self.__confFile.close()
160
160
161
161
162 def __initFromHardCode(self):
162 def __initFromHardCode(self):
163
163
164 self.__sender_email = self.__DEFAULT_SENDER_EMAIL
164 self.__sender_email = self.__DEFAULT_SENDER_EMAIL
165 self.__sender_pass = self.__DEFAULT_SENDER_PASS
165 self.__sender_pass = self.__DEFAULT_SENDER_PASS
166 self.__admin_email = self.__DEFAULT_ADMINISTRATOR_EMAIL
166 self.__admin_email = self.__DEFAULT_ADMINISTRATOR_EMAIL
167 self.__email_server = self.__DEFAULT_EMAIL_SERVER
167 self.__email_server = self.__DEFAULT_EMAIL_SERVER
168
168
169 def __readConfFile(self):
169 def __readConfFile(self):
170 """__readConfFile is a private helper function that reads information from the parsed config file.
170 """__readConfFile is a private helper function that reads information from the parsed config file.
171
171
172 Inputs: None
172 Inputs: None
173
173
174 Returns: Void.
174 Returns: Void.
175
175
176 Affects: Initializes class member variables that are found in the config file.
176 Affects: Initializes class member variables that are found in the config file.
177
177
178 Exceptions: MadrigalError thrown if any key not found.
178 Exceptions: MadrigalError thrown if any key not found.
179 """
179 """
180
180
181 # get the sender email
181 # get the sender email
182 try:
182 try:
183 self.__sender_email = self.__parser.get("schain", self.__SCHAIN_SENDER_EMAIL)
183 self.__sender_email = self.__parser.get("schain", self.__SCHAIN_SENDER_EMAIL)
184 except:
184 except:
185 self.__sender_email = self.__DEFAULT_SENDER_EMAIL
185 self.__sender_email = self.__DEFAULT_SENDER_EMAIL
186
186
187 # get the sender password
187 # get the sender password
188 try:
188 try:
189 self.__sender_pass = self.__parser.get("schain", self.__SCHAIN_SENDER_PASS)
189 self.__sender_pass = self.__parser.get("schain", self.__SCHAIN_SENDER_PASS)
190 except:
190 except:
191 self.__sender_pass = self.__DEFAULT_SENDER_PASS
191 self.__sender_pass = self.__DEFAULT_SENDER_PASS
192
192
193 # get the administrator email
193 # get the administrator email
194 try:
194 try:
195 self.__admin_email = self.__parser.get("schain", self.__SCHAIN_ADMINISTRATOR_EMAIL)
195 self.__admin_email = self.__parser.get("schain", self.__SCHAIN_ADMINISTRATOR_EMAIL)
196 except:
196 except:
197 self.__admin_email = self.__DEFAULT_ADMINISTRATOR_EMAIL
197 self.__admin_email = self.__DEFAULT_ADMINISTRATOR_EMAIL
198
198
199 # get the server email
199 # get the server email
200 try:
200 try:
201 self.__email_server = self.__parser.get("schain", self.__SCHAIN_EMAIL_SERVER)
201 self.__email_server = self.__parser.get("schain", self.__SCHAIN_EMAIL_SERVER)
202 except:
202 except:
203 self.__email_server = self.__DEFAULT_EMAIL_SERVER
203 self.__email_server = self.__DEFAULT_EMAIL_SERVER
204
204
205 def getEmailServer(self):
205 def getEmailServer(self):
206
206
207 return self.__email_server
207 return self.__email_server
208
208
209 def getSenderEmail(self):
209 def getSenderEmail(self):
210
210
211 return self.__sender_email
211 return self.__sender_email
212
212
213 def getSenderPass(self):
213 def getSenderPass(self):
214
214
215 return self.__sender_pass
215 return self.__sender_pass
216
216
217 def getAdminEmail(self):
217 def getAdminEmail(self):
218
218
219 return self.__admin_email
219 return self.__admin_email
220
220
221 class SchainNotify:
221 class SchainNotify:
222 """SchainNotify is an object used to send messages to an administrator about a Schain software.
222 """SchainNotify is an object used to send messages to an administrator about a Schain software.
223
223
224 This object provides functions needed to send messages to an administrator about a Schain , for now
224 This object provides functions needed to send messages to an administrator about a Schain , for now
225 only sendAlert, which sends an email to the site administrator found is ADMIN_EMAIL
225 only sendAlert, which sends an email to the site administrator found is ADMIN_EMAIL
226
226
227 Usage example:
227 Usage example:
228
228
229 import schainpy.admin
229 import schainpy.admin
230
230
231 try:
231 try:
232
232
233 adminObj = schainpy.admin.SchainNotify()
233 adminObj = schainpy.admin.SchainNotify()
234 adminObj.sendAlert('This is important!', 'Important Message')
234 adminObj.sendAlert('This is important!', 'Important Message')
235
235
236 except schainpy.admin.SchainError, e:
236 except schainpy.admin.SchainError, e:
237
237
238 print e.getExceptionStr()
238 print e.getExceptionStr()
239
239
240
240
241 Non-standard Python modules used:
241 Non-standard Python modules used:
242 None
242 None
243
243
244 Exceptions thrown: None - Note that SchainNotify tries every trick it knows to avoid
244 Exceptions thrown: None - Note that SchainNotify tries every trick it knows to avoid
245 throwing exceptions, since this is the class that will generally be called when there is a problem.
245 throwing exceptions, since this is the class that will generally be called when there is a problem.
246
246
247 Change history:
247 Change history:
248
248
249 Written by "Miguel Urco":mailto:miguel.urco@jro.igp.gob.pe Dec. 1, 2015
249 Written by "Miguel Urco":mailto:miguel.urco@jro.igp.gob.pe Dec. 1, 2015
250 """
250 """
251
251
252 #constants
252 #constants
253
253
254 def __init__(self):
254 def __init__(self):
255 """__init__ initializes SchainNotify by getting some basic information from SchainDB and SchainSite.
255 """__init__ initializes SchainNotify by getting some basic information from SchainDB and SchainSite.
256
256
257 Note that SchainNotify tries every trick it knows to avoid throwing exceptions, since
257 Note that SchainNotify tries every trick it knows to avoid throwing exceptions, since
258 this is the class that will generally be called when there is a problem.
258 this is the class that will generally be called when there is a problem.
259
259
260 Inputs: Existing SchainDB object, by default = None.
260 Inputs: Existing SchainDB object, by default = None.
261
261
262 Returns: void
262 Returns: void
263
263
264 Affects: Initializes self.__binDir.
264 Affects: Initializes self.__binDir.
265
265
266 Exceptions: None.
266 Exceptions: None.
267 """
267 """
268
268
269 # note that the main configuration file is unavailable
269 # note that the main configuration file is unavailable
270 # the best that can be done is send an email to root using localhost mailserver
270 # the best that can be done is send an email to root using localhost mailserver
271 confObj = SchainConfigure()
271 confObj = SchainConfigure()
272
272
273 self.__emailFromAddress = confObj.getSenderEmail()
273 self.__emailFromAddress = confObj.getSenderEmail()
274 self.__emailPass = confObj.getSenderPass()
274 self.__emailPass = confObj.getSenderPass()
275 self.__emailToAddress = confObj.getAdminEmail()
275 self.__emailToAddress = confObj.getAdminEmail()
276 self.__emailServer = confObj.getEmailServer()
276 self.__emailServer = confObj.getEmailServer()
277
277
278 def sendEmail(self, email_from, email_to, subject='Error running ...', message="", subtitle="", filename="", html_format=True):
278 def sendEmail(self, email_from, email_to, subject='Error running ...', message="", subtitle="", filename="", html_format=True):
279
279
280 if not email_to:
280 if not email_to:
281 return 0
281 return 0
282
282
283 if not self.__emailServer:
283 if not self.__emailServer:
284 return 0
284 return 0
285
285
286 log.success('Sending email to {}...'.format(email_to), 'System')
286 log.success('Sending email to {}...'.format(email_to), 'System')
287
287
288 msg = MIMEMultipart()
288 msg = MIMEMultipart()
289 msg['Subject'] = subject
289 msg['Subject'] = subject
290 msg['From'] = "(Python SChain API): " + email_from
290 msg['From'] = "(Python SChain API): " + email_from
291 msg['Reply-to'] = email_from
291 msg['Reply-to'] = email_from
292 msg['To'] = email_to
292 msg['To'] = email_to
293
293
294 # That is what u see if dont have an email reader:
294 # That is what u see if dont have an email reader:
295 msg.preamble = 'SChainPy'
295 msg.preamble = 'SChainPy'
296
296
297 if html_format:
297 if html_format:
298 message = "<h1> %s </h1>" %subject + "<h3>" + subtitle.replace("\n", "</h3><h3>\n") + "</h3>" + message.replace("\n", "<br>\n")
298 message = "<h1> %s </h1>" %subject + "<h3>" + subtitle.replace("\n", "</h3><h3>\n") + "</h3>" + message.replace("\n", "<br>\n")
299 message = "<html>\n" + message + '</html>'
299 message = "<html>\n" + message + '</html>'
300
300
301 # This is the textual part:
301 # This is the textual part:
302 part = MIMEText(message, "html")
302 part = MIMEText(message, "html")
303 else:
303 else:
304 message = subject + "\n" + subtitle + "\n" + message
304 message = subject + "\n" + subtitle + "\n" + message
305 part = MIMEText(message)
305 part = MIMEText(message)
306
306
307 msg.attach(part)
307 msg.attach(part)
308
308
309 if filename and os.path.isfile(filename):
309 if filename and os.path.isfile(filename):
310 # This is the binary part(The Attachment):
310 # This is the binary part(The Attachment):
311 part = MIMEApplication(open(filename,"rb").read())
311 part = MIMEApplication(open(filename,"rb").read())
312 part.add_header('Content-Disposition',
312 part.add_header('Content-Disposition',
313 'attachment',
313 'attachment',
314 filename=os.path.basename(filename))
314 filename=os.path.basename(filename))
315 msg.attach(part)
315 msg.attach(part)
316
316
317 # Create an instance in SMTP server
317 # Create an instance in SMTP server
318 try:
318 try:
319 smtp = smtplib.SMTP(self.__emailServer)
319 smtp = smtplib.SMTP(self.__emailServer)
320 except:
320 except:
321 log.error('Could not connect to server {}'.format(self.__emailServer), 'System')
321 log.error('Could not connect to server {}'.format(self.__emailServer), 'System')
322 return 0
322 return 0
323
323
324 # Start the server:
324 # Start the server:
325 # smtp.ehlo()
325 # smtp.ehlo()
326 if self.__emailPass:
326 if self.__emailPass:
327 smtp.login(self.__emailFromAddress, self.__emailPass)
327 smtp.login(self.__emailFromAddress, self.__emailPass)
328
328
329 # Send the email
329 # Send the email
330 try:
330 try:
331 smtp.sendmail(msg['From'], msg['To'], msg.as_string())
331 smtp.sendmail(msg['From'], msg['To'], msg.as_string())
332 except:
332 except:
333 log.error('Could not send the email to {}'.format(msg['To']), 'System')
333 log.error('Could not send the email to {}'.format(msg['To']), 'System')
334 smtp.quit()
334 smtp.quit()
335 return 0
335 return 0
336
336
337 smtp.quit()
337 smtp.quit()
338
338
339 log.success('Email sent ', 'System')
339 log.success('Email sent ', 'System')
340
340
341 return 1
341 return 1
342
342
343 def sendAlert(self, message, subject = "", subtitle="", filename=""):
343 def sendAlert(self, message, subject = "", subtitle="", filename=""):
344 """sendAlert sends an email with the given message and optional title.
344 """sendAlert sends an email with the given message and optional title.
345
345
346 Inputs: message (string), and optional title (string)
346 Inputs: message (string), and optional title (string)
347
347
348 Returns: void
348 Returns: void
349
349
350 Affects: none
350 Affects: none
351
351
352 Exceptions: None.
352 Exceptions: None.
353 """
353 """
354
354
355 if not self.__emailToAddress:
355 if not self.__emailToAddress:
356 return 0
356 return 0
357
357
358 print "***** Sending alert to %s *****" %self.__emailToAddress
358 print("***** Sending alert to %s *****" %self.__emailToAddress)
359 # set up message
359 # set up message
360
360
361 sent=self.sendEmail(email_from=self.__emailFromAddress,
361 sent=self.sendEmail(email_from=self.__emailFromAddress,
362 email_to=self.__emailToAddress,
362 email_to=self.__emailToAddress,
363 subject=subject,
363 subject=subject,
364 message=message,
364 message=message,
365 subtitle=subtitle,
365 subtitle=subtitle,
366 filename=filename)
366 filename=filename)
367
367
368 if not sent:
368 if not sent:
369 return 0
369 return 0
370
370
371 return 1
371 return 1
372
372
373 def notify(self, email, message, subject = "", subtitle="", filename=""):
373 def notify(self, email, message, subject = "", subtitle="", filename=""):
374 """notify sends an email with the given message and title to email.
374 """notify sends an email with the given message and title to email.
375
375
376 Inputs: email (string), message (string), and subject (string)
376 Inputs: email (string), message (string), and subject (string)
377
377
378 Returns: void
378 Returns: void
379
379
380 Affects: none
380 Affects: none
381
381
382 Exceptions: None.
382 Exceptions: None.
383 """
383 """
384
384
385 if email is None:
385 if email is None:
386 email = self.__emailToAddress
386 email = self.__emailToAddress
387
387
388 self.sendEmail(
388 self.sendEmail(
389 email_from=self.__emailFromAddress,
389 email_from=self.__emailFromAddress,
390 email_to=email,
390 email_to=email,
391 subject=subject,
391 subject=subject,
392 message=message,
392 message=message,
393 subtitle=subtitle,
393 subtitle=subtitle,
394 filename=filename
394 filename=filename
395 )
395 )
396
396
397
397
398 class SchainError(Exception):
398 class SchainError(Exception):
399 """SchainError is an exception class that is thrown for all known errors using Schain Py lib.
399 """SchainError is an exception class that is thrown for all known errors using Schain Py lib.
400
400
401 Usage example:
401 Usage example:
402
402
403 import sys, traceback
403 import sys, traceback
404 import schainpy.admin
404 import schainpy.admin
405
405
406 try:
406 try:
407
407
408 test = open('ImportantFile.txt', 'r')
408 test = open('ImportantFile.txt', 'r')
409
409
410 except:
410 except:
411
411
412 raise schainpy.admin.SchainError('ImportantFile.txt not opened!',
412 raise schainpy.admin.SchainError('ImportantFile.txt not opened!',
413 traceback.format_exception(sys.exc_info()[0],
413 traceback.format_exception(sys.exc_info()[0],
414 sys.exc_info()[1],
414 sys.exc_info()[1],
415 sys.exc_info()[2]))
415 sys.exc_info()[2]))
416 """
416 """
417
417
418
418
419 def __init__(self, strInterpretation, exceptionList=None):
419 def __init__(self, strInterpretation, exceptionList=None):
420 """ __init__ gathers the interpretation string along with all information from sys.exc_info().
420 """ __init__ gathers the interpretation string along with all information from sys.exc_info().
421
421
422 Inputs:
422 Inputs:
423 strIntepretation - A string representing the programmer's interpretation of
423 strIntepretation - A string representing the programmer's interpretation of
424 why the exception occurred
424 why the exception occurred
425
425
426 exceptionList - a list of strings completely describing the exception.
426 exceptionList - a list of strings completely describing the exception.
427 Generated by traceback.format_exception(sys.exc_info()[0],
427 Generated by traceback.format_exception(sys.exc_info()[0],
428 sys.exc_info()[1],
428 sys.exc_info()[1],
429 sys.exc_info()[2])
429 sys.exc_info()[2])
430
430
431 Returns: Void.
431 Returns: Void.
432
432
433 Affects: Initializes class member variables _strInterp, _strExcList.
433 Affects: Initializes class member variables _strInterp, _strExcList.
434
434
435 Exceptions: None.
435 Exceptions: None.
436 """
436 """
437
437
438 if not exceptionList:
438 if not exceptionList:
439 exceptionList = traceback.format_exception(sys.exc_info()[0],
439 exceptionList = traceback.format_exception(sys.exc_info()[0],
440 sys.exc_info()[1],
440 sys.exc_info()[1],
441 sys.exc_info()[2])
441 sys.exc_info()[2])
442
442
443 self._strInterp = strInterpretation
443 self._strInterp = strInterpretation
444 self._strExcList = exceptionList
444 self._strExcList = exceptionList
445
445
446
446
447 def getExceptionStr(self):
447 def getExceptionStr(self):
448 """ getExceptionStr returns a formatted string ready for printing completely describing the exception.
448 """ getExceptionStr returns a formatted string ready for printing completely describing the exception.
449
449
450 Inputs: None
450 Inputs: None
451
451
452 Returns: A formatted string ready for printing completely describing the exception.
452 Returns: A formatted string ready for printing completely describing the exception.
453
453
454 Affects: None
454 Affects: None
455
455
456 Exceptions: None.
456 Exceptions: None.
457 """
457 """
458 excStr = ''
458 excStr = ''
459 excStr = excStr + self._strInterp + '\n\n'
459 excStr = excStr + self._strInterp + '\n\n'
460
460
461 if self._strExcList != None:
461 if self._strExcList != None:
462 for item in self._strExcList:
462 for item in self._strExcList:
463 excStr = excStr + str(item) + '\n'
463 excStr = excStr + str(item) + '\n'
464
464
465 return excStr
465 return excStr
466
466
467 def __str__(self):
467 def __str__(self):
468
468
469 return(self.getExceptionStr())
469 return(self.getExceptionStr())
470
470
471
471
472 def getExceptionHtml(self):
472 def getExceptionHtml(self):
473 """ getExceptionHtml returns an Html formatted string completely describing the exception.
473 """ getExceptionHtml returns an Html formatted string completely describing the exception.
474
474
475 Inputs: None
475 Inputs: None
476
476
477 Returns: A formatted string ready for printing completely describing the exception.
477 Returns: A formatted string ready for printing completely describing the exception.
478
478
479 Affects: None
479 Affects: None
480
480
481 Exceptions: None.
481 Exceptions: None.
482 """
482 """
483
483
484 excStr = '<BR>The following Schain Python exception has occurred:\n<BR>'
484 excStr = '<BR>The following Schain Python exception has occurred:\n<BR>'
485 excStr = excStr + self._strInterp + '\n<BR>\n'
485 excStr = excStr + self._strInterp + '\n<BR>\n'
486
486
487 if self._strExcList != None:
487 if self._strExcList != None:
488 for item in self._strExcList:
488 for item in self._strExcList:
489 excStr = excStr + str(item) + '\n<BR>'
489 excStr = excStr + str(item) + '\n<BR>'
490
490
491 return excStr
491 return excStr
492
492
493 class SchainWarning(Exception):
493 class SchainWarning(Exception):
494 pass
494 pass
495
495
496
496
497 if __name__ == '__main__':
497 if __name__ == '__main__':
498
498
499 test = SchainNotify()
499 test = SchainNotify()
500
500
501 test.sendAlert('This is a message from the python module SchainNotify', 'Test from SchainNotify')
501 test.sendAlert('This is a message from the python module SchainNotify', 'Test from SchainNotify')
502
502
503 print 'Hopefully message sent - check.'
503 print('Hopefully message sent - check.') No newline at end of file
@@ -1,1342 +1,1342
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 math
10 import math
11 import time
11 import time
12 from multiprocessing import Process, cpu_count
12 from multiprocessing import Process, cpu_count
13
13
14 from xml.etree.ElementTree import ElementTree, Element, SubElement, tostring
14 from xml.etree.ElementTree import ElementTree, Element, SubElement, tostring
15 from xml.dom import minidom
15 from xml.dom import minidom
16
16
17 import schainpy
17 import schainpy
18 from schainpy.admin import Alarm, SchainWarning
18 from schainpy.admin import Alarm, SchainWarning
19 from schainpy.model import *
19 from schainpy.model import *
20 from schainpy.utils import log
20 from schainpy.utils import log
21
21
22 DTYPES = {
22 DTYPES = {
23 'Voltage': '.r',
23 'Voltage': '.r',
24 'Spectra': '.pdata'
24 'Spectra': '.pdata'
25 }
25 }
26
26
27
27
28 def MPProject(project, n=cpu_count()):
28 def MPProject(project, n=cpu_count()):
29 '''
29 '''
30 Project wrapper to run schain in n processes
30 Project wrapper to run schain in n processes
31 '''
31 '''
32
32
33 rconf = project.getReadUnitObj()
33 rconf = project.getReadUnitObj()
34 op = rconf.getOperationObj('run')
34 op = rconf.getOperationObj('run')
35 dt1 = op.getParameterValue('startDate')
35 dt1 = op.getParameterValue('startDate')
36 dt2 = op.getParameterValue('endDate')
36 dt2 = op.getParameterValue('endDate')
37 tm1 = op.getParameterValue('startTime')
37 tm1 = op.getParameterValue('startTime')
38 tm2 = op.getParameterValue('endTime')
38 tm2 = op.getParameterValue('endTime')
39 days = (dt2 - dt1).days
39 days = (dt2 - dt1).days
40
40
41 for day in range(days + 1):
41 for day in range(days + 1):
42 skip = 0
42 skip = 0
43 cursor = 0
43 cursor = 0
44 processes = []
44 processes = []
45 dt = dt1 + datetime.timedelta(day)
45 dt = dt1 + datetime.timedelta(day)
46 dt_str = dt.strftime('%Y/%m/%d')
46 dt_str = dt.strftime('%Y/%m/%d')
47 reader = JRODataReader()
47 reader = JRODataReader()
48 paths, files = reader.searchFilesOffLine(path=rconf.path,
48 paths, files = reader.searchFilesOffLine(path=rconf.path,
49 startDate=dt,
49 startDate=dt,
50 endDate=dt,
50 endDate=dt,
51 startTime=tm1,
51 startTime=tm1,
52 endTime=tm2,
52 endTime=tm2,
53 ext=DTYPES[rconf.datatype])
53 ext=DTYPES[rconf.datatype])
54 nFiles = len(files)
54 nFiles = len(files)
55 if nFiles == 0:
55 if nFiles == 0:
56 continue
56 continue
57 skip = int(math.ceil(nFiles / n))
57 skip = int(math.ceil(nFiles / n))
58 while nFiles > cursor * skip:
58 while nFiles > cursor * skip:
59 rconf.update(startDate=dt_str, endDate=dt_str, cursor=cursor,
59 rconf.update(startDate=dt_str, endDate=dt_str, cursor=cursor,
60 skip=skip)
60 skip=skip)
61 p = project.clone()
61 p = project.clone()
62 p.start()
62 p.start()
63 processes.append(p)
63 processes.append(p)
64 cursor += 1
64 cursor += 1
65
65
66 def beforeExit(exctype, value, trace):
66 def beforeExit(exctype, value, trace):
67 for process in processes:
67 for process in processes:
68 process.terminate()
68 process.terminate()
69 process.join()
69 process.join()
70 print traceback.print_tb(trace)
70 print(traceback.print_tb(trace))
71
71
72 sys.excepthook = beforeExit
72 sys.excepthook = beforeExit
73
73
74 for process in processes:
74 for process in processes:
75 process.join()
75 process.join()
76 process.terminate()
76 process.terminate()
77
77
78 time.sleep(3)
78 time.sleep(3)
79
79
80
80
81 class ParameterConf():
81 class ParameterConf():
82
82
83 id = None
83 id = None
84 name = None
84 name = None
85 value = None
85 value = None
86 format = None
86 format = None
87
87
88 __formated_value = None
88 __formated_value = None
89
89
90 ELEMENTNAME = 'Parameter'
90 ELEMENTNAME = 'Parameter'
91
91
92 def __init__(self):
92 def __init__(self):
93
93
94 self.format = 'str'
94 self.format = 'str'
95
95
96 def getElementName(self):
96 def getElementName(self):
97
97
98 return self.ELEMENTNAME
98 return self.ELEMENTNAME
99
99
100 def getValue(self):
100 def getValue(self):
101
101
102 value = self.value
102 value = self.value
103 format = self.format
103 format = self.format
104
104
105 if self.__formated_value != None:
105 if self.__formated_value != None:
106
106
107 return self.__formated_value
107 return self.__formated_value
108
108
109 if format == 'obj':
109 if format == 'obj':
110 return value
110 return value
111
111
112 if format == 'str':
112 if format == 'str':
113 self.__formated_value = str(value)
113 self.__formated_value = str(value)
114 return self.__formated_value
114 return self.__formated_value
115
115
116 if value == '':
116 if value == '':
117 raise ValueError, '%s: This parameter value is empty' % self.name
117 raise ValueError('%s: This parameter value is empty' % self.name)
118
118
119 if format == 'list':
119 if format == 'list':
120 strList = value.split(',')
120 strList = value.split(',')
121
121
122 self.__formated_value = strList
122 self.__formated_value = strList
123
123
124 return self.__formated_value
124 return self.__formated_value
125
125
126 if format == 'intlist':
126 if format == 'intlist':
127 '''
127 '''
128 Example:
128 Example:
129 value = (0,1,2)
129 value = (0,1,2)
130 '''
130 '''
131
131
132 new_value = ast.literal_eval(value)
132 new_value = ast.literal_eval(value)
133
133
134 if type(new_value) not in (tuple, list):
134 if type(new_value) not in (tuple, list):
135 new_value = [int(new_value)]
135 new_value = [int(new_value)]
136
136
137 self.__formated_value = new_value
137 self.__formated_value = new_value
138
138
139 return self.__formated_value
139 return self.__formated_value
140
140
141 if format == 'floatlist':
141 if format == 'floatlist':
142 '''
142 '''
143 Example:
143 Example:
144 value = (0.5, 1.4, 2.7)
144 value = (0.5, 1.4, 2.7)
145 '''
145 '''
146
146
147 new_value = ast.literal_eval(value)
147 new_value = ast.literal_eval(value)
148
148
149 if type(new_value) not in (tuple, list):
149 if type(new_value) not in (tuple, list):
150 new_value = [float(new_value)]
150 new_value = [float(new_value)]
151
151
152 self.__formated_value = new_value
152 self.__formated_value = new_value
153
153
154 return self.__formated_value
154 return self.__formated_value
155
155
156 if format == 'date':
156 if format == 'date':
157 strList = value.split('/')
157 strList = value.split('/')
158 intList = [int(x) for x in strList]
158 intList = [int(x) for x in strList]
159 date = datetime.date(intList[0], intList[1], intList[2])
159 date = datetime.date(intList[0], intList[1], intList[2])
160
160
161 self.__formated_value = date
161 self.__formated_value = date
162
162
163 return self.__formated_value
163 return self.__formated_value
164
164
165 if format == 'time':
165 if format == 'time':
166 strList = value.split(':')
166 strList = value.split(':')
167 intList = [int(x) for x in strList]
167 intList = [int(x) for x in strList]
168 time = datetime.time(intList[0], intList[1], intList[2])
168 time = datetime.time(intList[0], intList[1], intList[2])
169
169
170 self.__formated_value = time
170 self.__formated_value = time
171
171
172 return self.__formated_value
172 return self.__formated_value
173
173
174 if format == 'pairslist':
174 if format == 'pairslist':
175 '''
175 '''
176 Example:
176 Example:
177 value = (0,1),(1,2)
177 value = (0,1),(1,2)
178 '''
178 '''
179
179
180 new_value = ast.literal_eval(value)
180 new_value = ast.literal_eval(value)
181
181
182 if type(new_value) not in (tuple, list):
182 if type(new_value) not in (tuple, list):
183 raise ValueError, '%s has to be a tuple or list of pairs' % value
183 raise ValueError('%s has to be a tuple or list of pairs' % value)
184
184
185 if type(new_value[0]) not in (tuple, list):
185 if type(new_value[0]) not in (tuple, list):
186 if len(new_value) != 2:
186 if len(new_value) != 2:
187 raise ValueError, '%s has to be a tuple or list of pairs' % value
187 raise ValueError('%s has to be a tuple or list of pairs' % value)
188 new_value = [new_value]
188 new_value = [new_value]
189
189
190 for thisPair in new_value:
190 for thisPair in new_value:
191 if len(thisPair) != 2:
191 if len(thisPair) != 2:
192 raise ValueError, '%s has to be a tuple or list of pairs' % value
192 raise ValueError('%s has to be a tuple or list of pairs' % value)
193
193
194 self.__formated_value = new_value
194 self.__formated_value = new_value
195
195
196 return self.__formated_value
196 return self.__formated_value
197
197
198 if format == 'multilist':
198 if format == 'multilist':
199 '''
199 '''
200 Example:
200 Example:
201 value = (0,1,2),(3,4,5)
201 value = (0,1,2),(3,4,5)
202 '''
202 '''
203 multiList = ast.literal_eval(value)
203 multiList = ast.literal_eval(value)
204
204
205 if type(multiList[0]) == int:
205 if type(multiList[0]) == int:
206 multiList = ast.literal_eval('(' + value + ')')
206 multiList = ast.literal_eval('(' + value + ')')
207
207
208 self.__formated_value = multiList
208 self.__formated_value = multiList
209
209
210 return self.__formated_value
210 return self.__formated_value
211
211
212 if format == 'bool':
212 if format == 'bool':
213 value = int(value)
213 value = int(value)
214
214
215 if format == 'int':
215 if format == 'int':
216 value = float(value)
216 value = float(value)
217
217
218 format_func = eval(format)
218 format_func = eval(format)
219
219
220 self.__formated_value = format_func(value)
220 self.__formated_value = format_func(value)
221
221
222 return self.__formated_value
222 return self.__formated_value
223
223
224 def updateId(self, new_id):
224 def updateId(self, new_id):
225
225
226 self.id = str(new_id)
226 self.id = str(new_id)
227
227
228 def setup(self, id, name, value, format='str'):
228 def setup(self, id, name, value, format='str'):
229 self.id = str(id)
229 self.id = str(id)
230 self.name = name
230 self.name = name
231 if format == 'obj':
231 if format == 'obj':
232 self.value = value
232 self.value = value
233 else:
233 else:
234 self.value = str(value)
234 self.value = str(value)
235 self.format = str.lower(format)
235 self.format = str.lower(format)
236
236
237 self.getValue()
237 self.getValue()
238
238
239 return 1
239 return 1
240
240
241 def update(self, name, value, format='str'):
241 def update(self, name, value, format='str'):
242
242
243 self.name = name
243 self.name = name
244 self.value = str(value)
244 self.value = str(value)
245 self.format = format
245 self.format = format
246
246
247 def makeXml(self, opElement):
247 def makeXml(self, opElement):
248 if self.name not in ('queue',):
248 if self.name not in ('queue',):
249 parmElement = SubElement(opElement, self.ELEMENTNAME)
249 parmElement = SubElement(opElement, self.ELEMENTNAME)
250 parmElement.set('id', str(self.id))
250 parmElement.set('id', str(self.id))
251 parmElement.set('name', self.name)
251 parmElement.set('name', self.name)
252 parmElement.set('value', self.value)
252 parmElement.set('value', self.value)
253 parmElement.set('format', self.format)
253 parmElement.set('format', self.format)
254
254
255 def readXml(self, parmElement):
255 def readXml(self, parmElement):
256
256
257 self.id = parmElement.get('id')
257 self.id = parmElement.get('id')
258 self.name = parmElement.get('name')
258 self.name = parmElement.get('name')
259 self.value = parmElement.get('value')
259 self.value = parmElement.get('value')
260 self.format = str.lower(parmElement.get('format'))
260 self.format = str.lower(parmElement.get('format'))
261
261
262 # Compatible with old signal chain version
262 # Compatible with old signal chain version
263 if self.format == 'int' and self.name == 'idfigure':
263 if self.format == 'int' and self.name == 'idfigure':
264 self.name = 'id'
264 self.name = 'id'
265
265
266 def printattr(self):
266 def printattr(self):
267
267
268 print 'Parameter[%s]: name = %s, value = %s, format = %s' % (self.id, self.name, self.value, self.format)
268 print('Parameter[%s]: name = %s, value = %s, format = %s' % (self.id, self.name, self.value, self.format))
269
269
270
270
271 class OperationConf():
271 class OperationConf():
272
272
273 id = None
273 id = None
274 name = None
274 name = None
275 priority = None
275 priority = None
276 type = None
276 type = None
277
277
278 parmConfObjList = []
278 parmConfObjList = []
279
279
280 ELEMENTNAME = 'Operation'
280 ELEMENTNAME = 'Operation'
281
281
282 def __init__(self):
282 def __init__(self):
283
283
284 self.id = '0'
284 self.id = '0'
285 self.name = None
285 self.name = None
286 self.priority = None
286 self.priority = None
287 self.type = 'self'
287 self.type = 'self'
288
288
289 def __getNewId(self):
289 def __getNewId(self):
290
290
291 return int(self.id) * 10 + len(self.parmConfObjList) + 1
291 return int(self.id) * 10 + len(self.parmConfObjList) + 1
292
292
293 def updateId(self, new_id):
293 def updateId(self, new_id):
294
294
295 self.id = str(new_id)
295 self.id = str(new_id)
296
296
297 n = 1
297 n = 1
298 for parmObj in self.parmConfObjList:
298 for parmObj in self.parmConfObjList:
299
299
300 idParm = str(int(new_id) * 10 + n)
300 idParm = str(int(new_id) * 10 + n)
301 parmObj.updateId(idParm)
301 parmObj.updateId(idParm)
302
302
303 n += 1
303 n += 1
304
304
305 def getElementName(self):
305 def getElementName(self):
306
306
307 return self.ELEMENTNAME
307 return self.ELEMENTNAME
308
308
309 def getParameterObjList(self):
309 def getParameterObjList(self):
310
310
311 return self.parmConfObjList
311 return self.parmConfObjList
312
312
313 def getParameterObj(self, parameterName):
313 def getParameterObj(self, parameterName):
314
314
315 for parmConfObj in self.parmConfObjList:
315 for parmConfObj in self.parmConfObjList:
316
316
317 if parmConfObj.name != parameterName:
317 if parmConfObj.name != parameterName:
318 continue
318 continue
319
319
320 return parmConfObj
320 return parmConfObj
321
321
322 return None
322 return None
323
323
324 def getParameterObjfromValue(self, parameterValue):
324 def getParameterObjfromValue(self, parameterValue):
325
325
326 for parmConfObj in self.parmConfObjList:
326 for parmConfObj in self.parmConfObjList:
327
327
328 if parmConfObj.getValue() != parameterValue:
328 if parmConfObj.getValue() != parameterValue:
329 continue
329 continue
330
330
331 return parmConfObj.getValue()
331 return parmConfObj.getValue()
332
332
333 return None
333 return None
334
334
335 def getParameterValue(self, parameterName):
335 def getParameterValue(self, parameterName):
336
336
337 parameterObj = self.getParameterObj(parameterName)
337 parameterObj = self.getParameterObj(parameterName)
338
338
339 # if not parameterObj:
339 # if not parameterObj:
340 # return None
340 # return None
341
341
342 value = parameterObj.getValue()
342 value = parameterObj.getValue()
343
343
344 return value
344 return value
345
345
346 def getKwargs(self):
346 def getKwargs(self):
347
347
348 kwargs = {}
348 kwargs = {}
349
349
350 for parmConfObj in self.parmConfObjList:
350 for parmConfObj in self.parmConfObjList:
351 if self.name == 'run' and parmConfObj.name == 'datatype':
351 if self.name == 'run' and parmConfObj.name == 'datatype':
352 continue
352 continue
353
353
354 kwargs[parmConfObj.name] = parmConfObj.getValue()
354 kwargs[parmConfObj.name] = parmConfObj.getValue()
355
355
356 return kwargs
356 return kwargs
357
357
358 def setup(self, id, name, priority, type):
358 def setup(self, id, name, priority, type):
359
359
360 self.id = str(id)
360 self.id = str(id)
361 self.name = name
361 self.name = name
362 self.type = type
362 self.type = type
363 self.priority = priority
363 self.priority = priority
364
364
365 self.parmConfObjList = []
365 self.parmConfObjList = []
366
366
367 def removeParameters(self):
367 def removeParameters(self):
368
368
369 for obj in self.parmConfObjList:
369 for obj in self.parmConfObjList:
370 del obj
370 del obj
371
371
372 self.parmConfObjList = []
372 self.parmConfObjList = []
373
373
374 def addParameter(self, name, value, format='str'):
374 def addParameter(self, name, value, format='str'):
375
375
376 if value is None:
376 if value is None:
377 return None
377 return None
378 id = self.__getNewId()
378 id = self.__getNewId()
379
379
380 parmConfObj = ParameterConf()
380 parmConfObj = ParameterConf()
381 if not parmConfObj.setup(id, name, value, format):
381 if not parmConfObj.setup(id, name, value, format):
382 return None
382 return None
383
383
384 self.parmConfObjList.append(parmConfObj)
384 self.parmConfObjList.append(parmConfObj)
385
385
386 return parmConfObj
386 return parmConfObj
387
387
388 def changeParameter(self, name, value, format='str'):
388 def changeParameter(self, name, value, format='str'):
389
389
390 parmConfObj = self.getParameterObj(name)
390 parmConfObj = self.getParameterObj(name)
391 parmConfObj.update(name, value, format)
391 parmConfObj.update(name, value, format)
392
392
393 return parmConfObj
393 return parmConfObj
394
394
395 def makeXml(self, procUnitElement):
395 def makeXml(self, procUnitElement):
396
396
397 opElement = SubElement(procUnitElement, self.ELEMENTNAME)
397 opElement = SubElement(procUnitElement, self.ELEMENTNAME)
398 opElement.set('id', str(self.id))
398 opElement.set('id', str(self.id))
399 opElement.set('name', self.name)
399 opElement.set('name', self.name)
400 opElement.set('type', self.type)
400 opElement.set('type', self.type)
401 opElement.set('priority', str(self.priority))
401 opElement.set('priority', str(self.priority))
402
402
403 for parmConfObj in self.parmConfObjList:
403 for parmConfObj in self.parmConfObjList:
404 parmConfObj.makeXml(opElement)
404 parmConfObj.makeXml(opElement)
405
405
406 def readXml(self, opElement):
406 def readXml(self, opElement):
407
407
408 self.id = opElement.get('id')
408 self.id = opElement.get('id')
409 self.name = opElement.get('name')
409 self.name = opElement.get('name')
410 self.type = opElement.get('type')
410 self.type = opElement.get('type')
411 self.priority = opElement.get('priority')
411 self.priority = opElement.get('priority')
412
412
413 # Compatible with old signal chain version
413 # Compatible with old signal chain version
414 # Use of 'run' method instead 'init'
414 # Use of 'run' method instead 'init'
415 if self.type == 'self' and self.name == 'init':
415 if self.type == 'self' and self.name == 'init':
416 self.name = 'run'
416 self.name = 'run'
417
417
418 self.parmConfObjList = []
418 self.parmConfObjList = []
419
419
420 parmElementList = opElement.iter(ParameterConf().getElementName())
420 parmElementList = opElement.iter(ParameterConf().getElementName())
421
421
422 for parmElement in parmElementList:
422 for parmElement in parmElementList:
423 parmConfObj = ParameterConf()
423 parmConfObj = ParameterConf()
424 parmConfObj.readXml(parmElement)
424 parmConfObj.readXml(parmElement)
425
425
426 # Compatible with old signal chain version
426 # Compatible with old signal chain version
427 # If an 'plot' OPERATION is found, changes name operation by the value of its type PARAMETER
427 # If an 'plot' OPERATION is found, changes name operation by the value of its type PARAMETER
428 if self.type != 'self' and self.name == 'Plot':
428 if self.type != 'self' and self.name == 'Plot':
429 if parmConfObj.format == 'str' and parmConfObj.name == 'type':
429 if parmConfObj.format == 'str' and parmConfObj.name == 'type':
430 self.name = parmConfObj.value
430 self.name = parmConfObj.value
431 continue
431 continue
432
432
433 self.parmConfObjList.append(parmConfObj)
433 self.parmConfObjList.append(parmConfObj)
434
434
435 def printattr(self):
435 def printattr(self):
436
436
437 print '%s[%s]: name = %s, type = %s, priority = %s' % (self.ELEMENTNAME,
437 print('%s[%s]: name = %s, type = %s, priority = %s' % (self.ELEMENTNAME,
438 self.id,
438 self.id,
439 self.name,
439 self.name,
440 self.type,
440 self.type,
441 self.priority)
441 self.priority))
442
442
443 for parmConfObj in self.parmConfObjList:
443 for parmConfObj in self.parmConfObjList:
444 parmConfObj.printattr()
444 parmConfObj.printattr()
445
445
446 def createObject(self, plotter_queue=None):
446 def createObject(self, plotter_queue=None):
447
447
448 if self.type == 'self':
448 if self.type == 'self':
449 raise ValueError, 'This operation type cannot be created'
449 raise ValueError('This operation type cannot be created')
450
450
451 if self.type == 'plotter':
451 if self.type == 'plotter':
452 if not plotter_queue:
452 if not plotter_queue:
453 raise ValueError, 'plotter_queue is not defined. Use:\nmyProject = Project()\nmyProject.setPlotterQueue(plotter_queue)'
453 raise ValueError('plotter_queue is not defined. Use:\nmyProject = Project()\nmyProject.setPlotterQueue(plotter_queue)')
454
454
455 opObj = Plotter(self.name, plotter_queue)
455 opObj = Plotter(self.name, plotter_queue)
456
456
457 if self.type == 'external' or self.type == 'other':
457 if self.type == 'external' or self.type == 'other':
458
458
459 className = eval(self.name)
459 className = eval(self.name)
460 kwargs = self.getKwargs()
460 kwargs = self.getKwargs()
461
461
462 opObj = className(**kwargs)
462 opObj = className(**kwargs)
463
463
464 return opObj
464 return opObj
465
465
466
466
467 class ProcUnitConf():
467 class ProcUnitConf():
468
468
469 id = None
469 id = None
470 name = None
470 name = None
471 datatype = None
471 datatype = None
472 inputId = None
472 inputId = None
473 parentId = None
473 parentId = None
474
474
475 opConfObjList = []
475 opConfObjList = []
476
476
477 procUnitObj = None
477 procUnitObj = None
478 opObjList = []
478 opObjList = []
479
479
480 ELEMENTNAME = 'ProcUnit'
480 ELEMENTNAME = 'ProcUnit'
481
481
482 def __init__(self):
482 def __init__(self):
483
483
484 self.id = None
484 self.id = None
485 self.datatype = None
485 self.datatype = None
486 self.name = None
486 self.name = None
487 self.inputId = None
487 self.inputId = None
488
488
489 self.opConfObjList = []
489 self.opConfObjList = []
490
490
491 self.procUnitObj = None
491 self.procUnitObj = None
492 self.opObjDict = {}
492 self.opObjDict = {}
493
493
494 def __getPriority(self):
494 def __getPriority(self):
495
495
496 return len(self.opConfObjList) + 1
496 return len(self.opConfObjList) + 1
497
497
498 def __getNewId(self):
498 def __getNewId(self):
499
499
500 return int(self.id) * 10 + len(self.opConfObjList) + 1
500 return int(self.id) * 10 + len(self.opConfObjList) + 1
501
501
502 def getElementName(self):
502 def getElementName(self):
503
503
504 return self.ELEMENTNAME
504 return self.ELEMENTNAME
505
505
506 def getId(self):
506 def getId(self):
507
507
508 return self.id
508 return self.id
509
509
510 def updateId(self, new_id, parentId=parentId):
510 def updateId(self, new_id, parentId=parentId):
511
511
512 new_id = int(parentId) * 10 + (int(self.id) % 10)
512 new_id = int(parentId) * 10 + (int(self.id) % 10)
513 new_inputId = int(parentId) * 10 + (int(self.inputId) % 10)
513 new_inputId = int(parentId) * 10 + (int(self.inputId) % 10)
514
514
515 # If this proc unit has not inputs
515 # If this proc unit has not inputs
516 if self.inputId == '0':
516 if self.inputId == '0':
517 new_inputId = 0
517 new_inputId = 0
518
518
519 n = 1
519 n = 1
520 for opConfObj in self.opConfObjList:
520 for opConfObj in self.opConfObjList:
521
521
522 idOp = str(int(new_id) * 10 + n)
522 idOp = str(int(new_id) * 10 + n)
523 opConfObj.updateId(idOp)
523 opConfObj.updateId(idOp)
524
524
525 n += 1
525 n += 1
526
526
527 self.parentId = str(parentId)
527 self.parentId = str(parentId)
528 self.id = str(new_id)
528 self.id = str(new_id)
529 self.inputId = str(new_inputId)
529 self.inputId = str(new_inputId)
530
530
531 def getInputId(self):
531 def getInputId(self):
532
532
533 return self.inputId
533 return self.inputId
534
534
535 def getOperationObjList(self):
535 def getOperationObjList(self):
536
536
537 return self.opConfObjList
537 return self.opConfObjList
538
538
539 def getOperationObj(self, name=None):
539 def getOperationObj(self, name=None):
540
540
541 for opConfObj in self.opConfObjList:
541 for opConfObj in self.opConfObjList:
542
542
543 if opConfObj.name != name:
543 if opConfObj.name != name:
544 continue
544 continue
545
545
546 return opConfObj
546 return opConfObj
547
547
548 return None
548 return None
549
549
550 def getOpObjfromParamValue(self, value=None):
550 def getOpObjfromParamValue(self, value=None):
551
551
552 for opConfObj in self.opConfObjList:
552 for opConfObj in self.opConfObjList:
553 if opConfObj.getParameterObjfromValue(parameterValue=value) != value:
553 if opConfObj.getParameterObjfromValue(parameterValue=value) != value:
554 continue
554 continue
555 return opConfObj
555 return opConfObj
556 return None
556 return None
557
557
558 def getProcUnitObj(self):
558 def getProcUnitObj(self):
559
559
560 return self.procUnitObj
560 return self.procUnitObj
561
561
562 def setup(self, id, name, datatype, inputId, parentId=None):
562 def setup(self, id, name, datatype, inputId, parentId=None):
563
563
564 # Compatible with old signal chain version
564 # Compatible with old signal chain version
565 if datatype == None and name == None:
565 if datatype == None and name == None:
566 raise ValueError, 'datatype or name should be defined'
566 raise ValueError('datatype or name should be defined')
567
567
568 if name == None:
568 if name == None:
569 if 'Proc' in datatype:
569 if 'Proc' in datatype:
570 name = datatype
570 name = datatype
571 else:
571 else:
572 name = '%sProc' % (datatype)
572 name = '%sProc' % (datatype)
573
573
574 if datatype == None:
574 if datatype == None:
575 datatype = name.replace('Proc', '')
575 datatype = name.replace('Proc', '')
576
576
577 self.id = str(id)
577 self.id = str(id)
578 self.name = name
578 self.name = name
579 self.datatype = datatype
579 self.datatype = datatype
580 self.inputId = inputId
580 self.inputId = inputId
581 self.parentId = parentId
581 self.parentId = parentId
582
582
583 self.opConfObjList = []
583 self.opConfObjList = []
584
584
585 self.addOperation(name='run', optype='self')
585 self.addOperation(name='run', optype='self')
586
586
587 def removeOperations(self):
587 def removeOperations(self):
588
588
589 for obj in self.opConfObjList:
589 for obj in self.opConfObjList:
590 del obj
590 del obj
591
591
592 self.opConfObjList = []
592 self.opConfObjList = []
593 self.addOperation(name='run')
593 self.addOperation(name='run')
594
594
595 def addParameter(self, **kwargs):
595 def addParameter(self, **kwargs):
596 '''
596 '''
597 Add parameters to 'run' operation
597 Add parameters to 'run' operation
598 '''
598 '''
599 opObj = self.opConfObjList[0]
599 opObj = self.opConfObjList[0]
600
600
601 opObj.addParameter(**kwargs)
601 opObj.addParameter(**kwargs)
602
602
603 return opObj
603 return opObj
604
604
605 def addOperation(self, name, optype='self'):
605 def addOperation(self, name, optype='self'):
606
606
607 id = self.__getNewId()
607 id = self.__getNewId()
608 priority = self.__getPriority()
608 priority = self.__getPriority()
609
609
610 opConfObj = OperationConf()
610 opConfObj = OperationConf()
611 opConfObj.setup(id, name=name, priority=priority, type=optype)
611 opConfObj.setup(id, name=name, priority=priority, type=optype)
612
612
613 self.opConfObjList.append(opConfObj)
613 self.opConfObjList.append(opConfObj)
614
614
615 return opConfObj
615 return opConfObj
616
616
617 def makeXml(self, projectElement):
617 def makeXml(self, projectElement):
618
618
619 procUnitElement = SubElement(projectElement, self.ELEMENTNAME)
619 procUnitElement = SubElement(projectElement, self.ELEMENTNAME)
620 procUnitElement.set('id', str(self.id))
620 procUnitElement.set('id', str(self.id))
621 procUnitElement.set('name', self.name)
621 procUnitElement.set('name', self.name)
622 procUnitElement.set('datatype', self.datatype)
622 procUnitElement.set('datatype', self.datatype)
623 procUnitElement.set('inputId', str(self.inputId))
623 procUnitElement.set('inputId', str(self.inputId))
624
624
625 for opConfObj in self.opConfObjList:
625 for opConfObj in self.opConfObjList:
626 opConfObj.makeXml(procUnitElement)
626 opConfObj.makeXml(procUnitElement)
627
627
628 def readXml(self, upElement):
628 def readXml(self, upElement):
629
629
630 self.id = upElement.get('id')
630 self.id = upElement.get('id')
631 self.name = upElement.get('name')
631 self.name = upElement.get('name')
632 self.datatype = upElement.get('datatype')
632 self.datatype = upElement.get('datatype')
633 self.inputId = upElement.get('inputId')
633 self.inputId = upElement.get('inputId')
634
634
635 if self.ELEMENTNAME == 'ReadUnit':
635 if self.ELEMENTNAME == 'ReadUnit':
636 self.datatype = self.datatype.replace('Reader', '')
636 self.datatype = self.datatype.replace('Reader', '')
637
637
638 if self.ELEMENTNAME == 'ProcUnit':
638 if self.ELEMENTNAME == 'ProcUnit':
639 self.datatype = self.datatype.replace('Proc', '')
639 self.datatype = self.datatype.replace('Proc', '')
640
640
641 if self.inputId == 'None':
641 if self.inputId == 'None':
642 self.inputId = '0'
642 self.inputId = '0'
643
643
644 self.opConfObjList = []
644 self.opConfObjList = []
645
645
646 opElementList = upElement.iter(OperationConf().getElementName())
646 opElementList = upElement.iter(OperationConf().getElementName())
647
647
648 for opElement in opElementList:
648 for opElement in opElementList:
649 opConfObj = OperationConf()
649 opConfObj = OperationConf()
650 opConfObj.readXml(opElement)
650 opConfObj.readXml(opElement)
651 self.opConfObjList.append(opConfObj)
651 self.opConfObjList.append(opConfObj)
652
652
653 def printattr(self):
653 def printattr(self):
654
654
655 print '%s[%s]: name = %s, datatype = %s, inputId = %s' % (self.ELEMENTNAME,
655 print('%s[%s]: name = %s, datatype = %s, inputId = %s' % (self.ELEMENTNAME,
656 self.id,
656 self.id,
657 self.name,
657 self.name,
658 self.datatype,
658 self.datatype,
659 self.inputId)
659 self.inputId))
660
660
661 for opConfObj in self.opConfObjList:
661 for opConfObj in self.opConfObjList:
662 opConfObj.printattr()
662 opConfObj.printattr()
663
663
664 def getKwargs(self):
664 def getKwargs(self):
665
665
666 opObj = self.opConfObjList[0]
666 opObj = self.opConfObjList[0]
667 kwargs = opObj.getKwargs()
667 kwargs = opObj.getKwargs()
668
668
669 return kwargs
669 return kwargs
670
670
671 def createObjects(self, plotter_queue=None):
671 def createObjects(self, plotter_queue=None):
672
672
673 className = eval(self.name)
673 className = eval(self.name)
674 kwargs = self.getKwargs()
674 kwargs = self.getKwargs()
675 procUnitObj = className(**kwargs)
675 procUnitObj = className(**kwargs)
676
676
677 for opConfObj in self.opConfObjList:
677 for opConfObj in self.opConfObjList:
678
678
679 if opConfObj.type == 'self' and self.name == 'run':
679 if opConfObj.type == 'self' and self.name == 'run':
680 continue
680 continue
681 elif opConfObj.type == 'self':
681 elif opConfObj.type == 'self':
682 procUnitObj.addOperationKwargs(
682 procUnitObj.addOperationKwargs(
683 opConfObj.id, **opConfObj.getKwargs())
683 opConfObj.id, **opConfObj.getKwargs())
684 continue
684 continue
685
685
686 opObj = opConfObj.createObject(plotter_queue)
686 opObj = opConfObj.createObject(plotter_queue)
687
687
688 self.opObjDict[opConfObj.id] = opObj
688 self.opObjDict[opConfObj.id] = opObj
689
689
690 procUnitObj.addOperation(opObj, opConfObj.id)
690 procUnitObj.addOperation(opObj, opConfObj.id)
691
691
692 self.procUnitObj = procUnitObj
692 self.procUnitObj = procUnitObj
693
693
694 return procUnitObj
694 return procUnitObj
695
695
696 def run(self):
696 def run(self):
697
697
698 is_ok = False
698 is_ok = False
699
699
700 for opConfObj in self.opConfObjList:
700 for opConfObj in self.opConfObjList:
701
701
702 kwargs = {}
702 kwargs = {}
703 for parmConfObj in opConfObj.getParameterObjList():
703 for parmConfObj in opConfObj.getParameterObjList():
704 if opConfObj.name == 'run' and parmConfObj.name == 'datatype':
704 if opConfObj.name == 'run' and parmConfObj.name == 'datatype':
705 continue
705 continue
706
706
707 kwargs[parmConfObj.name] = parmConfObj.getValue()
707 kwargs[parmConfObj.name] = parmConfObj.getValue()
708
708
709 sts = self.procUnitObj.call(opType=opConfObj.type,
709 sts = self.procUnitObj.call(opType=opConfObj.type,
710 opName=opConfObj.name,
710 opName=opConfObj.name,
711 opId=opConfObj.id)
711 opId=opConfObj.id)
712
712
713 is_ok = is_ok or sts
713 is_ok = is_ok or sts
714
714
715 return is_ok
715 return is_ok
716
716
717 def close(self):
717 def close(self):
718
718
719 for opConfObj in self.opConfObjList:
719 for opConfObj in self.opConfObjList:
720 if opConfObj.type == 'self':
720 if opConfObj.type == 'self':
721 continue
721 continue
722
722
723 opObj = self.procUnitObj.getOperationObj(opConfObj.id)
723 opObj = self.procUnitObj.getOperationObj(opConfObj.id)
724 opObj.close()
724 opObj.close()
725
725
726 self.procUnitObj.close()
726 self.procUnitObj.close()
727
727
728 return
728 return
729
729
730
730
731 class ReadUnitConf(ProcUnitConf):
731 class ReadUnitConf(ProcUnitConf):
732
732
733 path = None
733 path = None
734 startDate = None
734 startDate = None
735 endDate = None
735 endDate = None
736 startTime = None
736 startTime = None
737 endTime = None
737 endTime = None
738
738
739 ELEMENTNAME = 'ReadUnit'
739 ELEMENTNAME = 'ReadUnit'
740
740
741 def __init__(self):
741 def __init__(self):
742
742
743 self.id = None
743 self.id = None
744 self.datatype = None
744 self.datatype = None
745 self.name = None
745 self.name = None
746 self.inputId = None
746 self.inputId = None
747
747
748 self.parentId = None
748 self.parentId = None
749
749
750 self.opConfObjList = []
750 self.opConfObjList = []
751 self.opObjList = []
751 self.opObjList = []
752
752
753 def getElementName(self):
753 def getElementName(self):
754
754
755 return self.ELEMENTNAME
755 return self.ELEMENTNAME
756
756
757 def setup(self, id, name, datatype, path='', startDate='', endDate='',
757 def setup(self, id, name, datatype, path='', startDate='', endDate='',
758 startTime='', endTime='', parentId=None, server=None, **kwargs):
758 startTime='', endTime='', parentId=None, server=None, **kwargs):
759
759
760 # Compatible with old signal chain version
760 # Compatible with old signal chain version
761 if datatype == None and name == None:
761 if datatype == None and name == None:
762 raise ValueError, 'datatype or name should be defined'
762 raise ValueError('datatype or name should be defined')
763 if name == None:
763 if name == None:
764 if 'Reader' in datatype:
764 if 'Reader' in datatype:
765 name = datatype
765 name = datatype
766 datatype = name.replace('Reader','')
766 datatype = name.replace('Reader','')
767 else:
767 else:
768 name = '{}Reader'.format(datatype)
768 name = '{}Reader'.format(datatype)
769 if datatype == None:
769 if datatype == None:
770 if 'Reader' in name:
770 if 'Reader' in name:
771 datatype = name.replace('Reader','')
771 datatype = name.replace('Reader','')
772 else:
772 else:
773 datatype = name
773 datatype = name
774 name = '{}Reader'.format(name)
774 name = '{}Reader'.format(name)
775
775
776 self.id = id
776 self.id = id
777 self.name = name
777 self.name = name
778 self.datatype = datatype
778 self.datatype = datatype
779 if path != '':
779 if path != '':
780 self.path = os.path.abspath(path)
780 self.path = os.path.abspath(path)
781 self.startDate = startDate
781 self.startDate = startDate
782 self.endDate = endDate
782 self.endDate = endDate
783 self.startTime = startTime
783 self.startTime = startTime
784 self.endTime = endTime
784 self.endTime = endTime
785 self.inputId = '0'
785 self.inputId = '0'
786 self.parentId = parentId
786 self.parentId = parentId
787 self.server = server
787 self.server = server
788 self.addRunOperation(**kwargs)
788 self.addRunOperation(**kwargs)
789
789
790 def update(self, **kwargs):
790 def update(self, **kwargs):
791
791
792 if 'datatype' in kwargs:
792 if 'datatype' in kwargs:
793 datatype = kwargs.pop('datatype')
793 datatype = kwargs.pop('datatype')
794 if 'Reader' in datatype:
794 if 'Reader' in datatype:
795 self.name = datatype
795 self.name = datatype
796 else:
796 else:
797 self.name = '%sReader' % (datatype)
797 self.name = '%sReader' % (datatype)
798 self.datatype = self.name.replace('Reader', '')
798 self.datatype = self.name.replace('Reader', '')
799
799
800 attrs = ('path', 'startDate', 'endDate',
800 attrs = ('path', 'startDate', 'endDate',
801 'startTime', 'endTime', 'parentId')
801 'startTime', 'endTime', 'parentId')
802
802
803 for attr in attrs:
803 for attr in attrs:
804 if attr in kwargs:
804 if attr in kwargs:
805 setattr(self, attr, kwargs.pop(attr))
805 setattr(self, attr, kwargs.pop(attr))
806
806
807 self.inputId = '0'
807 self.inputId = '0'
808 self.updateRunOperation(**kwargs)
808 self.updateRunOperation(**kwargs)
809
809
810 def removeOperations(self):
810 def removeOperations(self):
811
811
812 for obj in self.opConfObjList:
812 for obj in self.opConfObjList:
813 del obj
813 del obj
814
814
815 self.opConfObjList = []
815 self.opConfObjList = []
816
816
817 def addRunOperation(self, **kwargs):
817 def addRunOperation(self, **kwargs):
818
818
819 opObj = self.addOperation(name='run', optype='self')
819 opObj = self.addOperation(name='run', optype='self')
820
820
821 if self.server is None:
821 if self.server is None:
822 opObj.addParameter(
822 opObj.addParameter(
823 name='datatype', value=self.datatype, format='str')
823 name='datatype', value=self.datatype, format='str')
824 opObj.addParameter(name='path', value=self.path, format='str')
824 opObj.addParameter(name='path', value=self.path, format='str')
825 opObj.addParameter(
825 opObj.addParameter(
826 name='startDate', value=self.startDate, format='date')
826 name='startDate', value=self.startDate, format='date')
827 opObj.addParameter(
827 opObj.addParameter(
828 name='endDate', value=self.endDate, format='date')
828 name='endDate', value=self.endDate, format='date')
829 opObj.addParameter(
829 opObj.addParameter(
830 name='startTime', value=self.startTime, format='time')
830 name='startTime', value=self.startTime, format='time')
831 opObj.addParameter(
831 opObj.addParameter(
832 name='endTime', value=self.endTime, format='time')
832 name='endTime', value=self.endTime, format='time')
833
833
834 for key, value in kwargs.items():
834 for key, value in list(kwargs.items()):
835 opObj.addParameter(name=key, value=value,
835 opObj.addParameter(name=key, value=value,
836 format=type(value).__name__)
836 format=type(value).__name__)
837 else:
837 else:
838 opObj.addParameter(name='server', value=self.server, format='str')
838 opObj.addParameter(name='server', value=self.server, format='str')
839
839
840 return opObj
840 return opObj
841
841
842 def updateRunOperation(self, **kwargs):
842 def updateRunOperation(self, **kwargs):
843
843
844 opObj = self.getOperationObj(name='run')
844 opObj = self.getOperationObj(name='run')
845 opObj.removeParameters()
845 opObj.removeParameters()
846
846
847 opObj.addParameter(name='datatype', value=self.datatype, format='str')
847 opObj.addParameter(name='datatype', value=self.datatype, format='str')
848 opObj.addParameter(name='path', value=self.path, format='str')
848 opObj.addParameter(name='path', value=self.path, format='str')
849 opObj.addParameter(
849 opObj.addParameter(
850 name='startDate', value=self.startDate, format='date')
850 name='startDate', value=self.startDate, format='date')
851 opObj.addParameter(name='endDate', value=self.endDate, format='date')
851 opObj.addParameter(name='endDate', value=self.endDate, format='date')
852 opObj.addParameter(
852 opObj.addParameter(
853 name='startTime', value=self.startTime, format='time')
853 name='startTime', value=self.startTime, format='time')
854 opObj.addParameter(name='endTime', value=self.endTime, format='time')
854 opObj.addParameter(name='endTime', value=self.endTime, format='time')
855
855
856 for key, value in kwargs.items():
856 for key, value in list(kwargs.items()):
857 opObj.addParameter(name=key, value=value,
857 opObj.addParameter(name=key, value=value,
858 format=type(value).__name__)
858 format=type(value).__name__)
859
859
860 return opObj
860 return opObj
861
861
862 def readXml(self, upElement):
862 def readXml(self, upElement):
863
863
864 self.id = upElement.get('id')
864 self.id = upElement.get('id')
865 self.name = upElement.get('name')
865 self.name = upElement.get('name')
866 self.datatype = upElement.get('datatype')
866 self.datatype = upElement.get('datatype')
867 self.inputId = upElement.get('inputId')
867 self.inputId = upElement.get('inputId')
868
868
869 if self.ELEMENTNAME == 'ReadUnit':
869 if self.ELEMENTNAME == 'ReadUnit':
870 self.datatype = self.datatype.replace('Reader', '')
870 self.datatype = self.datatype.replace('Reader', '')
871
871
872 if self.inputId == 'None':
872 if self.inputId == 'None':
873 self.inputId = '0'
873 self.inputId = '0'
874
874
875 self.opConfObjList = []
875 self.opConfObjList = []
876
876
877 opElementList = upElement.iter(OperationConf().getElementName())
877 opElementList = upElement.iter(OperationConf().getElementName())
878
878
879 for opElement in opElementList:
879 for opElement in opElementList:
880 opConfObj = OperationConf()
880 opConfObj = OperationConf()
881 opConfObj.readXml(opElement)
881 opConfObj.readXml(opElement)
882 self.opConfObjList.append(opConfObj)
882 self.opConfObjList.append(opConfObj)
883
883
884 if opConfObj.name == 'run':
884 if opConfObj.name == 'run':
885 self.path = opConfObj.getParameterValue('path')
885 self.path = opConfObj.getParameterValue('path')
886 self.startDate = opConfObj.getParameterValue('startDate')
886 self.startDate = opConfObj.getParameterValue('startDate')
887 self.endDate = opConfObj.getParameterValue('endDate')
887 self.endDate = opConfObj.getParameterValue('endDate')
888 self.startTime = opConfObj.getParameterValue('startTime')
888 self.startTime = opConfObj.getParameterValue('startTime')
889 self.endTime = opConfObj.getParameterValue('endTime')
889 self.endTime = opConfObj.getParameterValue('endTime')
890
890
891
891
892 class Project(Process):
892 class Project(Process):
893
893
894 id = None
894 id = None
895 # name = None
895 # name = None
896 description = None
896 description = None
897 filename = None
897 filename = None
898
898
899 procUnitConfObjDict = None
899 procUnitConfObjDict = None
900
900
901 ELEMENTNAME = 'Project'
901 ELEMENTNAME = 'Project'
902
902
903 plotterQueue = None
903 plotterQueue = None
904
904
905 def __init__(self, plotter_queue=None):
905 def __init__(self, plotter_queue=None):
906
906
907 Process.__init__(self)
907 Process.__init__(self)
908 self.id = None
908 self.id = None
909 self.description = None
909 self.description = None
910 self.email = None
910 self.email = None
911 self.alarm = None
911 self.alarm = None
912 self.plotterQueue = plotter_queue
912 self.plotterQueue = plotter_queue
913 self.procUnitConfObjDict = {}
913 self.procUnitConfObjDict = {}
914
914
915 def __getNewId(self):
915 def __getNewId(self):
916
916
917 idList = self.procUnitConfObjDict.keys()
917 idList = list(self.procUnitConfObjDict.keys())
918
918
919 id = int(self.id) * 10
919 id = int(self.id) * 10
920
920
921 while True:
921 while True:
922 id += 1
922 id += 1
923
923
924 if str(id) in idList:
924 if str(id) in idList:
925 continue
925 continue
926
926
927 break
927 break
928
928
929 return str(id)
929 return str(id)
930
930
931 def getElementName(self):
931 def getElementName(self):
932
932
933 return self.ELEMENTNAME
933 return self.ELEMENTNAME
934
934
935 def getId(self):
935 def getId(self):
936
936
937 return self.id
937 return self.id
938
938
939 def updateId(self, new_id):
939 def updateId(self, new_id):
940
940
941 self.id = str(new_id)
941 self.id = str(new_id)
942
942
943 keyList = self.procUnitConfObjDict.keys()
943 keyList = list(self.procUnitConfObjDict.keys())
944 keyList.sort()
944 keyList.sort()
945
945
946 n = 1
946 n = 1
947 newProcUnitConfObjDict = {}
947 newProcUnitConfObjDict = {}
948
948
949 for procKey in keyList:
949 for procKey in keyList:
950
950
951 procUnitConfObj = self.procUnitConfObjDict[procKey]
951 procUnitConfObj = self.procUnitConfObjDict[procKey]
952 idProcUnit = str(int(self.id) * 10 + n)
952 idProcUnit = str(int(self.id) * 10 + n)
953 procUnitConfObj.updateId(idProcUnit, parentId=self.id)
953 procUnitConfObj.updateId(idProcUnit, parentId=self.id)
954 newProcUnitConfObjDict[idProcUnit] = procUnitConfObj
954 newProcUnitConfObjDict[idProcUnit] = procUnitConfObj
955 n += 1
955 n += 1
956
956
957 self.procUnitConfObjDict = newProcUnitConfObjDict
957 self.procUnitConfObjDict = newProcUnitConfObjDict
958
958
959 def setup(self, id, name='', description='', email=None, alarm=[]):
959 def setup(self, id, name='', description='', email=None, alarm=[]):
960
960
961 print
961 print()
962 print '*' * 60
962 print('*' * 60)
963 print ' Starting SIGNAL CHAIN PROCESSING v%s ' % schainpy.__version__
963 print(' Starting SIGNAL CHAIN PROCESSING v%s ' % schainpy.__version__)
964 print '*' * 60
964 print('*' * 60)
965 print
965 print()
966 self.id = str(id)
966 self.id = str(id)
967 self.description = description
967 self.description = description
968 self.email = email
968 self.email = email
969 self.alarm = alarm
969 self.alarm = alarm
970
970
971 def update(self, **kwargs):
971 def update(self, **kwargs):
972
972
973 for key, value in kwargs.items():
973 for key, value in list(kwargs.items()):
974 setattr(self, key, value)
974 setattr(self, key, value)
975
975
976 def clone(self):
976 def clone(self):
977
977
978 p = Project()
978 p = Project()
979 p.procUnitConfObjDict = self.procUnitConfObjDict
979 p.procUnitConfObjDict = self.procUnitConfObjDict
980 return p
980 return p
981
981
982 def addReadUnit(self, id=None, datatype=None, name=None, **kwargs):
982 def addReadUnit(self, id=None, datatype=None, name=None, **kwargs):
983
983
984 if id is None:
984 if id is None:
985 idReadUnit = self.__getNewId()
985 idReadUnit = self.__getNewId()
986 else:
986 else:
987 idReadUnit = str(id)
987 idReadUnit = str(id)
988
988
989 readUnitConfObj = ReadUnitConf()
989 readUnitConfObj = ReadUnitConf()
990 readUnitConfObj.setup(idReadUnit, name, datatype,
990 readUnitConfObj.setup(idReadUnit, name, datatype,
991 parentId=self.id, **kwargs)
991 parentId=self.id, **kwargs)
992
992
993 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
993 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
994
994
995 return readUnitConfObj
995 return readUnitConfObj
996
996
997 def addProcUnit(self, inputId='0', datatype=None, name=None):
997 def addProcUnit(self, inputId='0', datatype=None, name=None):
998
998
999 idProcUnit = self.__getNewId()
999 idProcUnit = self.__getNewId()
1000
1000
1001 procUnitConfObj = ProcUnitConf()
1001 procUnitConfObj = ProcUnitConf()
1002 procUnitConfObj.setup(idProcUnit, name, datatype,
1002 procUnitConfObj.setup(idProcUnit, name, datatype,
1003 inputId, parentId=self.id)
1003 inputId, parentId=self.id)
1004
1004
1005 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
1005 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
1006
1006
1007 return procUnitConfObj
1007 return procUnitConfObj
1008
1008
1009 def removeProcUnit(self, id):
1009 def removeProcUnit(self, id):
1010
1010
1011 if id in self.procUnitConfObjDict.keys():
1011 if id in list(self.procUnitConfObjDict.keys()):
1012 self.procUnitConfObjDict.pop(id)
1012 self.procUnitConfObjDict.pop(id)
1013
1013
1014 def getReadUnitId(self):
1014 def getReadUnitId(self):
1015
1015
1016 readUnitConfObj = self.getReadUnitObj()
1016 readUnitConfObj = self.getReadUnitObj()
1017
1017
1018 return readUnitConfObj.id
1018 return readUnitConfObj.id
1019
1019
1020 def getReadUnitObj(self):
1020 def getReadUnitObj(self):
1021
1021
1022 for obj in self.procUnitConfObjDict.values():
1022 for obj in list(self.procUnitConfObjDict.values()):
1023 if obj.getElementName() == 'ReadUnit':
1023 if obj.getElementName() == 'ReadUnit':
1024 return obj
1024 return obj
1025
1025
1026 return None
1026 return None
1027
1027
1028 def getProcUnitObj(self, id=None, name=None):
1028 def getProcUnitObj(self, id=None, name=None):
1029
1029
1030 if id != None:
1030 if id != None:
1031 return self.procUnitConfObjDict[id]
1031 return self.procUnitConfObjDict[id]
1032
1032
1033 if name != None:
1033 if name != None:
1034 return self.getProcUnitObjByName(name)
1034 return self.getProcUnitObjByName(name)
1035
1035
1036 return None
1036 return None
1037
1037
1038 def getProcUnitObjByName(self, name):
1038 def getProcUnitObjByName(self, name):
1039
1039
1040 for obj in self.procUnitConfObjDict.values():
1040 for obj in list(self.procUnitConfObjDict.values()):
1041 if obj.name == name:
1041 if obj.name == name:
1042 return obj
1042 return obj
1043
1043
1044 return None
1044 return None
1045
1045
1046 def procUnitItems(self):
1046 def procUnitItems(self):
1047
1047
1048 return self.procUnitConfObjDict.items()
1048 return list(self.procUnitConfObjDict.items())
1049
1049
1050 def makeXml(self):
1050 def makeXml(self):
1051
1051
1052 projectElement = Element('Project')
1052 projectElement = Element('Project')
1053 projectElement.set('id', str(self.id))
1053 projectElement.set('id', str(self.id))
1054 projectElement.set('name', self.name)
1054 projectElement.set('name', self.name)
1055 projectElement.set('description', self.description)
1055 projectElement.set('description', self.description)
1056
1056
1057 for procUnitConfObj in self.procUnitConfObjDict.values():
1057 for procUnitConfObj in list(self.procUnitConfObjDict.values()):
1058 procUnitConfObj.makeXml(projectElement)
1058 procUnitConfObj.makeXml(projectElement)
1059
1059
1060 self.projectElement = projectElement
1060 self.projectElement = projectElement
1061
1061
1062 def writeXml(self, filename=None):
1062 def writeXml(self, filename=None):
1063
1063
1064 if filename == None:
1064 if filename == None:
1065 if self.filename:
1065 if self.filename:
1066 filename = self.filename
1066 filename = self.filename
1067 else:
1067 else:
1068 filename = 'schain.xml'
1068 filename = 'schain.xml'
1069
1069
1070 if not filename:
1070 if not filename:
1071 print 'filename has not been defined. Use setFilename(filename) for do it.'
1071 print('filename has not been defined. Use setFilename(filename) for do it.')
1072 return 0
1072 return 0
1073
1073
1074 abs_file = os.path.abspath(filename)
1074 abs_file = os.path.abspath(filename)
1075
1075
1076 if not os.access(os.path.dirname(abs_file), os.W_OK):
1076 if not os.access(os.path.dirname(abs_file), os.W_OK):
1077 print 'No write permission on %s' % os.path.dirname(abs_file)
1077 print('No write permission on %s' % os.path.dirname(abs_file))
1078 return 0
1078 return 0
1079
1079
1080 if os.path.isfile(abs_file) and not(os.access(abs_file, os.W_OK)):
1080 if os.path.isfile(abs_file) and not(os.access(abs_file, os.W_OK)):
1081 print 'File %s already exists and it could not be overwriten' % abs_file
1081 print('File %s already exists and it could not be overwriten' % abs_file)
1082 return 0
1082 return 0
1083
1083
1084 self.makeXml()
1084 self.makeXml()
1085
1085
1086 ElementTree(self.projectElement).write(abs_file, method='xml')
1086 ElementTree(self.projectElement).write(abs_file, method='xml')
1087
1087
1088 self.filename = abs_file
1088 self.filename = abs_file
1089
1089
1090 return 1
1090 return 1
1091
1091
1092 def readXml(self, filename=None):
1092 def readXml(self, filename=None):
1093
1093
1094 if not filename:
1094 if not filename:
1095 print 'filename is not defined'
1095 print('filename is not defined')
1096 return 0
1096 return 0
1097
1097
1098 abs_file = os.path.abspath(filename)
1098 abs_file = os.path.abspath(filename)
1099
1099
1100 if not os.path.isfile(abs_file):
1100 if not os.path.isfile(abs_file):
1101 print '%s file does not exist' % abs_file
1101 print('%s file does not exist' % abs_file)
1102 return 0
1102 return 0
1103
1103
1104 self.projectElement = None
1104 self.projectElement = None
1105 self.procUnitConfObjDict = {}
1105 self.procUnitConfObjDict = {}
1106
1106
1107 try:
1107 try:
1108 self.projectElement = ElementTree().parse(abs_file)
1108 self.projectElement = ElementTree().parse(abs_file)
1109 except:
1109 except:
1110 print 'Error reading %s, verify file format' % filename
1110 print('Error reading %s, verify file format' % filename)
1111 return 0
1111 return 0
1112
1112
1113 self.project = self.projectElement.tag
1113 self.project = self.projectElement.tag
1114
1114
1115 self.id = self.projectElement.get('id')
1115 self.id = self.projectElement.get('id')
1116 self.name = self.projectElement.get('name')
1116 self.name = self.projectElement.get('name')
1117 self.description = self.projectElement.get('description')
1117 self.description = self.projectElement.get('description')
1118
1118
1119 readUnitElementList = self.projectElement.iter(
1119 readUnitElementList = self.projectElement.iter(
1120 ReadUnitConf().getElementName())
1120 ReadUnitConf().getElementName())
1121
1121
1122 for readUnitElement in readUnitElementList:
1122 for readUnitElement in readUnitElementList:
1123 readUnitConfObj = ReadUnitConf()
1123 readUnitConfObj = ReadUnitConf()
1124 readUnitConfObj.readXml(readUnitElement)
1124 readUnitConfObj.readXml(readUnitElement)
1125
1125
1126 if readUnitConfObj.parentId == None:
1126 if readUnitConfObj.parentId == None:
1127 readUnitConfObj.parentId = self.id
1127 readUnitConfObj.parentId = self.id
1128
1128
1129 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
1129 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
1130
1130
1131 procUnitElementList = self.projectElement.iter(
1131 procUnitElementList = self.projectElement.iter(
1132 ProcUnitConf().getElementName())
1132 ProcUnitConf().getElementName())
1133
1133
1134 for procUnitElement in procUnitElementList:
1134 for procUnitElement in procUnitElementList:
1135 procUnitConfObj = ProcUnitConf()
1135 procUnitConfObj = ProcUnitConf()
1136 procUnitConfObj.readXml(procUnitElement)
1136 procUnitConfObj.readXml(procUnitElement)
1137
1137
1138 if procUnitConfObj.parentId == None:
1138 if procUnitConfObj.parentId == None:
1139 procUnitConfObj.parentId = self.id
1139 procUnitConfObj.parentId = self.id
1140
1140
1141 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
1141 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
1142
1142
1143 self.filename = abs_file
1143 self.filename = abs_file
1144
1144
1145 return 1
1145 return 1
1146
1146
1147 def printattr(self):
1147 def printattr(self):
1148
1148
1149 print 'Project[%s]: name = %s, description = %s' % (self.id,
1149 print('Project[%s]: name = %s, description = %s' % (self.id,
1150 self.name,
1150 self.name,
1151 self.description)
1151 self.description))
1152
1152
1153 for procUnitConfObj in self.procUnitConfObjDict.values():
1153 for procUnitConfObj in list(self.procUnitConfObjDict.values()):
1154 procUnitConfObj.printattr()
1154 procUnitConfObj.printattr()
1155
1155
1156 def createObjects(self):
1156 def createObjects(self):
1157
1157
1158 for procUnitConfObj in self.procUnitConfObjDict.values():
1158 for procUnitConfObj in list(self.procUnitConfObjDict.values()):
1159 procUnitConfObj.createObjects(self.plotterQueue)
1159 procUnitConfObj.createObjects(self.plotterQueue)
1160
1160
1161 def __connect(self, objIN, thisObj):
1161 def __connect(self, objIN, thisObj):
1162
1162
1163 thisObj.setInput(objIN.getOutputObj())
1163 thisObj.setInput(objIN.getOutputObj())
1164
1164
1165 def connectObjects(self):
1165 def connectObjects(self):
1166
1166
1167 for thisPUConfObj in self.procUnitConfObjDict.values():
1167 for thisPUConfObj in list(self.procUnitConfObjDict.values()):
1168
1168
1169 inputId = thisPUConfObj.getInputId()
1169 inputId = thisPUConfObj.getInputId()
1170
1170
1171 if int(inputId) == 0:
1171 if int(inputId) == 0:
1172 continue
1172 continue
1173
1173
1174 # Get input object
1174 # Get input object
1175 puConfINObj = self.procUnitConfObjDict[inputId]
1175 puConfINObj = self.procUnitConfObjDict[inputId]
1176 puObjIN = puConfINObj.getProcUnitObj()
1176 puObjIN = puConfINObj.getProcUnitObj()
1177
1177
1178 # Get current object
1178 # Get current object
1179 thisPUObj = thisPUConfObj.getProcUnitObj()
1179 thisPUObj = thisPUConfObj.getProcUnitObj()
1180
1180
1181 self.__connect(puObjIN, thisPUObj)
1181 self.__connect(puObjIN, thisPUObj)
1182
1182
1183 def __handleError(self, procUnitConfObj, modes=None, stdout=True):
1183 def __handleError(self, procUnitConfObj, modes=None, stdout=True):
1184
1184
1185 import socket
1185 import socket
1186
1186
1187 if modes is None:
1187 if modes is None:
1188 modes = self.alarm
1188 modes = self.alarm
1189
1189
1190 if not self.alarm:
1190 if not self.alarm:
1191 modes = []
1191 modes = []
1192
1192
1193 err = traceback.format_exception(sys.exc_info()[0],
1193 err = traceback.format_exception(sys.exc_info()[0],
1194 sys.exc_info()[1],
1194 sys.exc_info()[1],
1195 sys.exc_info()[2])
1195 sys.exc_info()[2])
1196
1196
1197 log.error('{}'.format(err[-1]), procUnitConfObj.name)
1197 log.error('{}'.format(err[-1]), procUnitConfObj.name)
1198
1198
1199 message = ''.join(err)
1199 message = ''.join(err)
1200
1200
1201 if stdout:
1201 if stdout:
1202 sys.stderr.write(message)
1202 sys.stderr.write(message)
1203
1203
1204 subject = 'SChain v%s: Error running %s\n' % (
1204 subject = 'SChain v%s: Error running %s\n' % (
1205 schainpy.__version__, procUnitConfObj.name)
1205 schainpy.__version__, procUnitConfObj.name)
1206
1206
1207 subtitle = '%s: %s\n' % (
1207 subtitle = '%s: %s\n' % (
1208 procUnitConfObj.getElementName(), procUnitConfObj.name)
1208 procUnitConfObj.getElementName(), procUnitConfObj.name)
1209 subtitle += 'Hostname: %s\n' % socket.gethostbyname(
1209 subtitle += 'Hostname: %s\n' % socket.gethostbyname(
1210 socket.gethostname())
1210 socket.gethostname())
1211 subtitle += 'Working directory: %s\n' % os.path.abspath('./')
1211 subtitle += 'Working directory: %s\n' % os.path.abspath('./')
1212 subtitle += 'Configuration file: %s\n' % self.filename
1212 subtitle += 'Configuration file: %s\n' % self.filename
1213 subtitle += 'Time: %s\n' % str(datetime.datetime.now())
1213 subtitle += 'Time: %s\n' % str(datetime.datetime.now())
1214
1214
1215 readUnitConfObj = self.getReadUnitObj()
1215 readUnitConfObj = self.getReadUnitObj()
1216 if readUnitConfObj:
1216 if readUnitConfObj:
1217 subtitle += '\nInput parameters:\n'
1217 subtitle += '\nInput parameters:\n'
1218 subtitle += '[Data path = %s]\n' % readUnitConfObj.path
1218 subtitle += '[Data path = %s]\n' % readUnitConfObj.path
1219 subtitle += '[Data type = %s]\n' % readUnitConfObj.datatype
1219 subtitle += '[Data type = %s]\n' % readUnitConfObj.datatype
1220 subtitle += '[Start date = %s]\n' % readUnitConfObj.startDate
1220 subtitle += '[Start date = %s]\n' % readUnitConfObj.startDate
1221 subtitle += '[End date = %s]\n' % readUnitConfObj.endDate
1221 subtitle += '[End date = %s]\n' % readUnitConfObj.endDate
1222 subtitle += '[Start time = %s]\n' % readUnitConfObj.startTime
1222 subtitle += '[Start time = %s]\n' % readUnitConfObj.startTime
1223 subtitle += '[End time = %s]\n' % readUnitConfObj.endTime
1223 subtitle += '[End time = %s]\n' % readUnitConfObj.endTime
1224
1224
1225 a = Alarm(
1225 a = Alarm(
1226 modes=modes,
1226 modes=modes,
1227 email=self.email,
1227 email=self.email,
1228 message=message,
1228 message=message,
1229 subject=subject,
1229 subject=subject,
1230 subtitle=subtitle,
1230 subtitle=subtitle,
1231 filename=self.filename
1231 filename=self.filename
1232 )
1232 )
1233
1233
1234 return a
1234 return a
1235
1235
1236 def isPaused(self):
1236 def isPaused(self):
1237 return 0
1237 return 0
1238
1238
1239 def isStopped(self):
1239 def isStopped(self):
1240 return 0
1240 return 0
1241
1241
1242 def runController(self):
1242 def runController(self):
1243 '''
1243 '''
1244 returns 0 when this process has been stopped, 1 otherwise
1244 returns 0 when this process has been stopped, 1 otherwise
1245 '''
1245 '''
1246
1246
1247 if self.isPaused():
1247 if self.isPaused():
1248 print 'Process suspended'
1248 print('Process suspended')
1249
1249
1250 while True:
1250 while True:
1251 time.sleep(0.1)
1251 time.sleep(0.1)
1252
1252
1253 if not self.isPaused():
1253 if not self.isPaused():
1254 break
1254 break
1255
1255
1256 if self.isStopped():
1256 if self.isStopped():
1257 break
1257 break
1258
1258
1259 print 'Process reinitialized'
1259 print('Process reinitialized')
1260
1260
1261 if self.isStopped():
1261 if self.isStopped():
1262 print 'Process stopped'
1262 print('Process stopped')
1263 return 0
1263 return 0
1264
1264
1265 return 1
1265 return 1
1266
1266
1267 def setFilename(self, filename):
1267 def setFilename(self, filename):
1268
1268
1269 self.filename = filename
1269 self.filename = filename
1270
1270
1271 def setPlotterQueue(self, plotter_queue):
1271 def setPlotterQueue(self, plotter_queue):
1272
1272
1273 raise NotImplementedError, 'Use schainpy.controller_api.ControllerThread instead Project class'
1273 raise NotImplementedError('Use schainpy.controller_api.ControllerThread instead Project class')
1274
1274
1275 def getPlotterQueue(self):
1275 def getPlotterQueue(self):
1276
1276
1277 raise NotImplementedError, 'Use schainpy.controller_api.ControllerThread instead Project class'
1277 raise NotImplementedError('Use schainpy.controller_api.ControllerThread instead Project class')
1278
1278
1279 def useExternalPlotter(self):
1279 def useExternalPlotter(self):
1280
1280
1281 raise NotImplementedError, 'Use schainpy.controller_api.ControllerThread instead Project class'
1281 raise NotImplementedError('Use schainpy.controller_api.ControllerThread instead Project class')
1282
1282
1283 def run(self):
1283 def run(self):
1284
1284
1285 log.success('Starting {}'.format(self.name), tag='')
1285 log.success('Starting {}'.format(self.name), tag='')
1286 self.start_time = time.time()
1286 self.start_time = time.time()
1287 self.createObjects()
1287 self.createObjects()
1288 self.connectObjects()
1288 self.connectObjects()
1289
1289
1290 keyList = self.procUnitConfObjDict.keys()
1290 keyList = list(self.procUnitConfObjDict.keys())
1291 keyList.sort()
1291 keyList.sort()
1292
1292
1293 err = None
1293 err = None
1294
1294
1295 while(True):
1295 while(True):
1296
1296
1297 is_ok = False
1297 is_ok = False
1298
1298
1299 for procKey in keyList:
1299 for procKey in keyList:
1300
1300
1301 procUnitConfObj = self.procUnitConfObjDict[procKey]
1301 procUnitConfObj = self.procUnitConfObjDict[procKey]
1302
1302
1303 try:
1303 try:
1304 sts = procUnitConfObj.run()
1304 sts = procUnitConfObj.run()
1305 is_ok = is_ok or sts
1305 is_ok = is_ok or sts
1306 except SchainWarning:
1306 except SchainWarning:
1307 err = self.__handleError(procUnitConfObj, modes=[2, 3], stdout=False)
1307 err = self.__handleError(procUnitConfObj, modes=[2, 3], stdout=False)
1308 is_ok = False
1308 is_ok = False
1309 break
1309 break
1310 except KeyboardInterrupt:
1310 except KeyboardInterrupt:
1311 is_ok = False
1311 is_ok = False
1312 break
1312 break
1313 except ValueError, e:
1313 except ValueError as e:
1314 time.sleep(0.5)
1314 time.sleep(0.5)
1315 err = self.__handleError(procUnitConfObj)
1315 err = self.__handleError(procUnitConfObj)
1316 is_ok = False
1316 is_ok = False
1317 break
1317 break
1318 except:
1318 except:
1319 time.sleep(0.5)
1319 time.sleep(0.5)
1320 err = self.__handleError(procUnitConfObj)
1320 err = self.__handleError(procUnitConfObj)
1321 is_ok = False
1321 is_ok = False
1322 break
1322 break
1323
1323
1324 # If every process unit finished so end process
1324 # If every process unit finished so end process
1325 if not(is_ok):
1325 if not(is_ok):
1326 break
1326 break
1327
1327
1328 if not self.runController():
1328 if not self.runController():
1329 break
1329 break
1330
1330
1331 # Closing every process
1331 # Closing every process
1332 for procKey in keyList:
1332 for procKey in keyList:
1333 procUnitConfObj = self.procUnitConfObjDict[procKey]
1333 procUnitConfObj = self.procUnitConfObjDict[procKey]
1334 procUnitConfObj.close()
1334 procUnitConfObj.close()
1335
1335
1336 if err is not None:
1336 if err is not None:
1337 err.start()
1337 err.start()
1338 # err.join()
1338 # err.join()
1339
1339
1340 log.success('{} finished (time: {}s)'.format(
1340 log.success('{} finished (time: {}s)'.format(
1341 self.name,
1341 self.name,
1342 time.time()-self.start_time))
1342 time.time()-self.start_time)) No newline at end of file
@@ -1,179 +1,179
1 import threading
1 import threading
2 from Queue import Queue
2 from queue import Queue
3
3
4 from schainpy.controller import Project
4 from schainpy.controller import Project
5 from schainpy.model.graphics.jroplotter import PlotManager
5 from schainpy.model.graphics.jroplotter import PlotManager
6
6
7 class ControllerThread(threading.Thread, Project):
7 class ControllerThread(threading.Thread, Project):
8
8
9 def __init__(self, plotter_queue=None):
9 def __init__(self, plotter_queue=None):
10
10
11 threading.Thread.__init__(self)
11 threading.Thread.__init__(self)
12 Project.__init__(self, plotter_queue)
12 Project.__init__(self, plotter_queue)
13
13
14 self.setDaemon(True)
14 self.setDaemon(True)
15
15
16 self.lock = threading.Lock()
16 self.lock = threading.Lock()
17 self.control = { 'stop':False, 'pause':False }
17 self.control = { 'stop':False, 'pause':False }
18
18
19 def __del__(self):
19 def __del__(self):
20
20
21 self.control['stop'] = True
21 self.control['stop'] = True
22
22
23 def stop(self):
23 def stop(self):
24
24
25 self.lock.acquire()
25 self.lock.acquire()
26
26
27 self.control['stop'] = True
27 self.control['stop'] = True
28
28
29 self.lock.release()
29 self.lock.release()
30
30
31 def pause(self):
31 def pause(self):
32
32
33 self.lock.acquire()
33 self.lock.acquire()
34
34
35 self.control['pause'] = not(self.control['pause'])
35 self.control['pause'] = not(self.control['pause'])
36 paused = self.control['pause']
36 paused = self.control['pause']
37
37
38 self.lock.release()
38 self.lock.release()
39
39
40 return paused
40 return paused
41
41
42 def isPaused(self):
42 def isPaused(self):
43
43
44 self.lock.acquire()
44 self.lock.acquire()
45 paused = self.control['pause']
45 paused = self.control['pause']
46 self.lock.release()
46 self.lock.release()
47
47
48 return paused
48 return paused
49
49
50 def isStopped(self):
50 def isStopped(self):
51
51
52 self.lock.acquire()
52 self.lock.acquire()
53 stopped = self.control['stop']
53 stopped = self.control['stop']
54 self.lock.release()
54 self.lock.release()
55
55
56 return stopped
56 return stopped
57
57
58 def run(self):
58 def run(self):
59 self.control['stop'] = False
59 self.control['stop'] = False
60 self.control['pause'] = False
60 self.control['pause'] = False
61
61
62 self.writeXml()
62 self.writeXml()
63
63
64 self.createObjects()
64 self.createObjects()
65 self.connectObjects()
65 self.connectObjects()
66 Project.run(self)
66 Project.run(self)
67
67
68 def isRunning(self):
68 def isRunning(self):
69
69
70 return self.is_alive()
70 return self.is_alive()
71
71
72 def isFinished(self):
72 def isFinished(self):
73
73
74 return not self.is_alive()
74 return not self.is_alive()
75
75
76 def setPlotters(self):
76 def setPlotters(self):
77
77
78 plotterList = PlotManager.plotterList
78 plotterList = PlotManager.plotterList
79
79
80 for thisPUConfObj in self.procUnitConfObjDict.values():
80 for thisPUConfObj in list(self.procUnitConfObjDict.values()):
81
81
82 inputId = thisPUConfObj.getInputId()
82 inputId = thisPUConfObj.getInputId()
83
83
84 if int(inputId) == 0:
84 if int(inputId) == 0:
85 continue
85 continue
86
86
87 for thisOpObj in thisPUConfObj.getOperationObjList():
87 for thisOpObj in thisPUConfObj.getOperationObjList():
88
88
89 if thisOpObj.type == "self":
89 if thisOpObj.type == "self":
90 continue
90 continue
91
91
92 if thisOpObj.name in plotterList:
92 if thisOpObj.name in plotterList:
93 thisOpObj.type = "other"
93 thisOpObj.type = "other"
94
94
95 def setPlotterQueue(self, plotter_queue):
95 def setPlotterQueue(self, plotter_queue):
96
96
97 self.plotterQueue = plotter_queue
97 self.plotterQueue = plotter_queue
98
98
99 def getPlotterQueue(self):
99 def getPlotterQueue(self):
100
100
101 return self.plotterQueue
101 return self.plotterQueue
102
102
103 def useExternalPlotter(self):
103 def useExternalPlotter(self):
104
104
105 self.plotterQueue = Queue(10)
105 self.plotterQueue = Queue(10)
106 self.setPlotters()
106 self.setPlotters()
107
107
108 plotManagerObj = PlotManager(self.plotterQueue)
108 plotManagerObj = PlotManager(self.plotterQueue)
109 plotManagerObj.setController(self)
109 plotManagerObj.setController(self)
110
110
111 return plotManagerObj
111 return plotManagerObj
112
112
113 # from PyQt4 import QtCore
113 # from PyQt4 import QtCore
114 # from PyQt4.QtCore import SIGNAL
114 # from PyQt4.QtCore import SIGNAL
115 #
115 #
116 # class ControllerQThread(QtCore.QThread, Project):
116 # class ControllerQThread(QtCore.QThread, Project):
117 #
117 #
118 # def __init__(self, filename):
118 # def __init__(self, filename):
119 #
119 #
120 # QtCore.QThread.__init__(self)
120 # QtCore.QThread.__init__(self)
121 # Project.__init__(self)
121 # Project.__init__(self)
122 #
122 #
123 # self.filename = filename
123 # self.filename = filename
124 #
124 #
125 # self.lock = threading.Lock()
125 # self.lock = threading.Lock()
126 # self.control = {'stop':False, 'pause':False}
126 # self.control = {'stop':False, 'pause':False}
127 #
127 #
128 # def __del__(self):
128 # def __del__(self):
129 #
129 #
130 # self.control['stop'] = True
130 # self.control['stop'] = True
131 # self.wait()
131 # self.wait()
132 #
132 #
133 # def stop(self):
133 # def stop(self):
134 #
134 #
135 # self.lock.acquire()
135 # self.lock.acquire()
136 #
136 #
137 # self.control['stop'] = True
137 # self.control['stop'] = True
138 #
138 #
139 # self.lock.release()
139 # self.lock.release()
140 #
140 #
141 # def pause(self):
141 # def pause(self):
142 #
142 #
143 # self.lock.acquire()
143 # self.lock.acquire()
144 #
144 #
145 # self.control['pause'] = not(self.control['pause'])
145 # self.control['pause'] = not(self.control['pause'])
146 # paused = self.control['pause']
146 # paused = self.control['pause']
147 #
147 #
148 # self.lock.release()
148 # self.lock.release()
149 #
149 #
150 # return paused
150 # return paused
151 #
151 #
152 # def isPaused(self):
152 # def isPaused(self):
153 #
153 #
154 # self.lock.acquire()
154 # self.lock.acquire()
155 # paused = self.control['pause']
155 # paused = self.control['pause']
156 # self.lock.release()
156 # self.lock.release()
157 #
157 #
158 # return paused
158 # return paused
159 #
159 #
160 # def isStopped(self):
160 # def isStopped(self):
161 #
161 #
162 # self.lock.acquire()
162 # self.lock.acquire()
163 # stopped = self.control['stop']
163 # stopped = self.control['stop']
164 # self.lock.release()
164 # self.lock.release()
165 #
165 #
166 # return stopped
166 # return stopped
167 #
167 #
168 # def run(self):
168 # def run(self):
169 #
169 #
170 # self.control['stop'] = False
170 # self.control['stop'] = False
171 # self.control['pause'] = False
171 # self.control['pause'] = False
172 #
172 #
173 # self.readXml(self.filename)
173 # self.readXml(self.filename)
174 # self.createObjects()
174 # self.createObjects()
175 # self.connectObjects()
175 # self.connectObjects()
176 # self.emit( SIGNAL( "jobStarted( PyQt_PyObject )" ), 1)
176 # self.emit( SIGNAL( "jobStarted( PyQt_PyObject )" ), 1)
177 # Project.run(self)
177 # Project.run(self)
178 # self.emit( SIGNAL( "jobFinished( PyQt_PyObject )" ), 1)
178 # self.emit( SIGNAL( "jobFinished( PyQt_PyObject )" ), 1)
179 #
179 # No newline at end of file
@@ -1,12 +1,12
1 #from schainpy.model.data.jrodata import *
1 #from schainpy.model.data.jrodata import *
2 # from schainpy.model.io.jrodataIO import *
2 # from schainpy.model.io.jrodataIO import *
3 # from schainpy.model.proc.jroprocessing import *
3 # from schainpy.model.proc.jroprocessing import *
4 # from schainpy.model.graphics.jroplot import *
4 # from schainpy.model.graphics.jroplot import *
5 # from schainpy.model.utils.jroutils import *
5 # from schainpy.model.utils.jroutils import *
6 # from schainpy.serializer import *
6 # from schainpy.serializer import *
7
7
8 from graphics import *
8 from .graphics import *
9 from data import *
9 from .data import *
10 from io import *
10 from .io import *
11 from proc import *
11 from .proc import *
12 from utils import *
12 from .utils import *
@@ -1,404 +1,404
1 '''
1 '''
2
2
3 $Author: murco $
3 $Author: murco $
4 $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $
4 $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $
5 '''
5 '''
6 import sys
6 import sys
7 import numpy
7 import numpy
8 import copy
8 import copy
9 import datetime
9 import datetime
10 from __builtin__ import None
10
11
11
12 SPEED_OF_LIGHT = 299792458
12 SPEED_OF_LIGHT = 299792458
13 SPEED_OF_LIGHT = 3e8
13 SPEED_OF_LIGHT = 3e8
14
14
15 FILE_STRUCTURE = numpy.dtype([ #HEADER 48bytes
15 FILE_STRUCTURE = numpy.dtype([ #HEADER 48bytes
16 ('FileMgcNumber','<u4'), #0x23020100
16 ('FileMgcNumber','<u4'), #0x23020100
17 ('nFDTdataRecors','<u4'), #No Of FDT data records in this file (0 or more)
17 ('nFDTdataRecors','<u4'), #No Of FDT data records in this file (0 or more)
18 ('RadarUnitId','<u4'),
18 ('RadarUnitId','<u4'),
19 ('SiteName','<s32'), #Null terminated
19 ('SiteName','<s32'), #Null terminated
20 ])
20 ])
21
21
22 RECORD_STRUCTURE = numpy.dtype([ #RECORD HEADER 180+20N bytes
22 RECORD_STRUCTURE = numpy.dtype([ #RECORD HEADER 180+20N bytes
23 ('RecMgcNumber','<u4'), #0x23030001
23 ('RecMgcNumber','<u4'), #0x23030001
24 ('RecCounter','<u4'), #Record counter(0,1, ...)
24 ('RecCounter','<u4'), #Record counter(0,1, ...)
25 ('Off2StartNxtRec','<u4'), #Offset to start of next record form start of this record
25 ('Off2StartNxtRec','<u4'), #Offset to start of next record form start of this record
26 ('Off2StartData','<u4'), #Offset to start of data from start of this record
26 ('Off2StartData','<u4'), #Offset to start of data from start of this record
27 ('EpTimeStamp','<i4'), #Epoch time stamp of start of acquisition (seconds)
27 ('EpTimeStamp','<i4'), #Epoch time stamp of start of acquisition (seconds)
28 ('msCompTimeStamp','<u4'), #Millisecond component of time stamp (0,...,999)
28 ('msCompTimeStamp','<u4'), #Millisecond component of time stamp (0,...,999)
29 ('ExpTagName','<s32'), #Experiment tag name (null terminated)
29 ('ExpTagName','<s32'), #Experiment tag name (null terminated)
30 ('ExpComment','<s32'), #Experiment comment (null terminated)
30 ('ExpComment','<s32'), #Experiment comment (null terminated)
31 ('SiteLatDegrees','<f4'), #Site latitude (from GPS) in degrees (positive implies North)
31 ('SiteLatDegrees','<f4'), #Site latitude (from GPS) in degrees (positive implies North)
32 ('SiteLongDegrees','<f4'), #Site longitude (from GPS) in degrees (positive implies East)
32 ('SiteLongDegrees','<f4'), #Site longitude (from GPS) in degrees (positive implies East)
33 ('RTCgpsStatus','<u4'), #RTC GPS engine status (0=SEEK, 1=LOCK, 2=NOT FITTED, 3=UNAVAILABLE)
33 ('RTCgpsStatus','<u4'), #RTC GPS engine status (0=SEEK, 1=LOCK, 2=NOT FITTED, 3=UNAVAILABLE)
34 ('TransmitFrec','<u4'), #Transmit frequency (Hz)
34 ('TransmitFrec','<u4'), #Transmit frequency (Hz)
35 ('ReceiveFrec','<u4'), #Receive frequency
35 ('ReceiveFrec','<u4'), #Receive frequency
36 ('FirstOsciFrec','<u4'), #First local oscillator frequency (Hz)
36 ('FirstOsciFrec','<u4'), #First local oscillator frequency (Hz)
37 ('Polarisation','<u4'), #(0="O", 1="E", 2="linear 1", 3="linear2")
37 ('Polarisation','<u4'), #(0="O", 1="E", 2="linear 1", 3="linear2")
38 ('ReceiverFiltSett','<u4'), #Receiver filter settings (0,1,2,3)
38 ('ReceiverFiltSett','<u4'), #Receiver filter settings (0,1,2,3)
39 ('nModesInUse','<u4'), #Number of modes in use (1 or 2)
39 ('nModesInUse','<u4'), #Number of modes in use (1 or 2)
40 ('DualModeIndex','<u4'), #Dual Mode index number for these data (0 or 1)
40 ('DualModeIndex','<u4'), #Dual Mode index number for these data (0 or 1)
41 ('DualModeRange','<u4'), #Dual Mode range correction for these data (m)
41 ('DualModeRange','<u4'), #Dual Mode range correction for these data (m)
42 ('nDigChannels','<u4'), #Number of digital channels acquired (2*N)
42 ('nDigChannels','<u4'), #Number of digital channels acquired (2*N)
43 ('SampResolution','<u4'), #Sampling resolution (meters)
43 ('SampResolution','<u4'), #Sampling resolution (meters)
44 ('nRangeGatesSamp','<u4'), #Number of range gates sampled
44 ('nRangeGatesSamp','<u4'), #Number of range gates sampled
45 ('StartRangeSamp','<u4'), #Start range of sampling (meters)
45 ('StartRangeSamp','<u4'), #Start range of sampling (meters)
46 ('PRFhz','<u4'), #PRF (Hz)
46 ('PRFhz','<u4'), #PRF (Hz)
47 ('Integrations','<u4'), #Integrations
47 ('Integrations','<u4'), #Integrations
48 ('nDataPointsTrsf','<u4'), #Number of data points transformed
48 ('nDataPointsTrsf','<u4'), #Number of data points transformed
49 ('nReceiveBeams','<u4'), #Number of receive beams stored in file (1 or N)
49 ('nReceiveBeams','<u4'), #Number of receive beams stored in file (1 or N)
50 ('nSpectAverages','<u4'), #Number of spectral averages
50 ('nSpectAverages','<u4'), #Number of spectral averages
51 ('FFTwindowingInd','<u4'), #FFT windowing index (0 = no window)
51 ('FFTwindowingInd','<u4'), #FFT windowing index (0 = no window)
52 ('BeamAngleAzim','<f4'), #Beam steer angle (azimuth) in degrees (clockwise from true North)
52 ('BeamAngleAzim','<f4'), #Beam steer angle (azimuth) in degrees (clockwise from true North)
53 ('BeamAngleZen','<f4'), #Beam steer angle (zenith) in degrees (0=> vertical)
53 ('BeamAngleZen','<f4'), #Beam steer angle (zenith) in degrees (0=> vertical)
54 ('AntennaCoord','<f24'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
54 ('AntennaCoord','<f24'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
55 ('RecPhaseCalibr','<f12'), #Receiver phase calibration (degrees) - N values
55 ('RecPhaseCalibr','<f12'), #Receiver phase calibration (degrees) - N values
56 ('RecAmpCalibr','<f12'), #Receiver amplitude calibration (ratio relative to receiver one) - N values
56 ('RecAmpCalibr','<f12'), #Receiver amplitude calibration (ratio relative to receiver one) - N values
57 ('ReceiverGaindB','<u12'), #Receiver gains in dB - N values
57 ('ReceiverGaindB','<u12'), #Receiver gains in dB - N values
58 ])
58 ])
59
59
60
60
61 class Header(object):
61 class Header(object):
62
62
63 def __init__(self):
63 def __init__(self):
64 raise NotImplementedError
64 raise NotImplementedError
65
65
66
66
67 def read(self):
67 def read(self):
68
68
69 raise NotImplementedError
69 raise NotImplementedError
70
70
71 def write(self):
71 def write(self):
72
72
73 raise NotImplementedError
73 raise NotImplementedError
74
74
75 def printInfo(self):
75 def printInfo(self):
76
76
77 message = "#"*50 + "\n"
77 message = "#"*50 + "\n"
78 message += self.__class__.__name__.upper() + "\n"
78 message += self.__class__.__name__.upper() + "\n"
79 message += "#"*50 + "\n"
79 message += "#"*50 + "\n"
80
80
81 keyList = self.__dict__.keys()
81 keyList = list(self.__dict__.keys())
82 keyList.sort()
82 keyList.sort()
83
83
84 for key in keyList:
84 for key in keyList:
85 message += "%s = %s" %(key, self.__dict__[key]) + "\n"
85 message += "%s = %s" %(key, self.__dict__[key]) + "\n"
86
86
87 if "size" not in keyList:
87 if "size" not in keyList:
88 attr = getattr(self, "size")
88 attr = getattr(self, "size")
89
89
90 if attr:
90 if attr:
91 message += "%s = %s" %("size", attr) + "\n"
91 message += "%s = %s" %("size", attr) + "\n"
92
92
93 print message
93 print(message)
94
94
95 class FileHeader(Header):
95 class FileHeader(Header):
96
96
97 FileMgcNumber= None
97 FileMgcNumber= None
98 nFDTdataRecors=None #No Of FDT data records in this file (0 or more)
98 nFDTdataRecors=None #No Of FDT data records in this file (0 or more)
99 RadarUnitId= None
99 RadarUnitId= None
100 SiteName= None
100 SiteName= None
101
101
102 #__LOCALTIME = None
102 #__LOCALTIME = None
103
103
104 def __init__(self, useLocalTime=True):
104 def __init__(self, useLocalTime=True):
105
105
106 self.FileMgcNumber= 0 #0x23020100
106 self.FileMgcNumber= 0 #0x23020100
107 self.nFDTdataRecors=0 #No Of FDT data records in this file (0 or more)
107 self.nFDTdataRecors=0 #No Of FDT data records in this file (0 or more)
108 self.RadarUnitId= 0
108 self.RadarUnitId= 0
109 self.SiteName= ""
109 self.SiteName= ""
110 self.size = 48
110 self.size = 48
111
111
112 #self.useLocalTime = useLocalTime
112 #self.useLocalTime = useLocalTime
113
113
114 def read(self, fp):
114 def read(self, fp):
115
115
116 try:
116 try:
117 header = numpy.fromfile(fp, FILE_STRUCTURE,1)
117 header = numpy.fromfile(fp, FILE_STRUCTURE,1)
118 ''' numpy.fromfile(file, dtype, count, sep='')
118 ''' numpy.fromfile(file, dtype, count, sep='')
119 file : file or str
119 file : file or str
120 Open file object or filename.
120 Open file object or filename.
121
121
122 dtype : data-type
122 dtype : data-type
123 Data type of the returned array. For binary files, it is used to determine
123 Data type of the returned array. For binary files, it is used to determine
124 the size and byte-order of the items in the file.
124 the size and byte-order of the items in the file.
125
125
126 count : int
126 count : int
127 Number of items to read. -1 means all items (i.e., the complete file).
127 Number of items to read. -1 means all items (i.e., the complete file).
128
128
129 sep : str
129 sep : str
130 Separator between items if file is a text file. Empty (“”) separator means
130 Separator between items if file is a text file. Empty (“”) separator means
131 the file should be treated as binary. Spaces (” ”) in the separator match zero
131 the file should be treated as binary. Spaces (” ”) in the separator match zero
132 or more whitespace characters. A separator consisting only of spaces must match
132 or more whitespace characters. A separator consisting only of spaces must match
133 at least one whitespace.
133 at least one whitespace.
134
134
135 '''
135 '''
136
136
137 except Exception, e:
137 except Exception as e:
138 print "FileHeader: "
138 print("FileHeader: ")
139 print eBasicHeader
139 print(eBasicHeader)
140 return 0
140 return 0
141
141
142 self.FileMgcNumber= byte(header['FileMgcNumber'][0])
142 self.FileMgcNumber= byte(header['FileMgcNumber'][0])
143 self.nFDTdataRecors=int(header['nFDTdataRecors'][0]) #No Of FDT data records in this file (0 or more)
143 self.nFDTdataRecors=int(header['nFDTdataRecors'][0]) #No Of FDT data records in this file (0 or more)
144 self.RadarUnitId= int(header['RadarUnitId'][0])
144 self.RadarUnitId= int(header['RadarUnitId'][0])
145 self.SiteName= char(header['SiteName'][0])
145 self.SiteName= char(header['SiteName'][0])
146
146
147
147
148 if self.size <48:
148 if self.size <48:
149 return 0
149 return 0
150
150
151 return 1
151 return 1
152
152
153 def write(self, fp):
153 def write(self, fp):
154
154
155 headerTuple = (self.FileMgcNumber,
155 headerTuple = (self.FileMgcNumber,
156 self.nFDTdataRecors,
156 self.nFDTdataRecors,
157 self.RadarUnitId,
157 self.RadarUnitId,
158 self.SiteName,
158 self.SiteName,
159 self.size)
159 self.size)
160
160
161
161
162 header = numpy.array(headerTuple, FILE_STRUCTURE)
162 header = numpy.array(headerTuple, FILE_STRUCTURE)
163 # numpy.array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0)
163 # numpy.array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0)
164 header.tofile(fp)
164 header.tofile(fp)
165 ''' ndarray.tofile(fid, sep, format) Write array to a file as text or binary (default).
165 ''' ndarray.tofile(fid, sep, format) Write array to a file as text or binary (default).
166
166
167 fid : file or str
167 fid : file or str
168 An open file object, or a string containing a filename.
168 An open file object, or a string containing a filename.
169
169
170 sep : str
170 sep : str
171 Separator between array items for text output. If “” (empty), a binary file is written,
171 Separator between array items for text output. If “” (empty), a binary file is written,
172 equivalent to file.write(a.tobytes()).
172 equivalent to file.write(a.tobytes()).
173
173
174 format : str
174 format : str
175 Format string for text file output. Each entry in the array is formatted to text by
175 Format string for text file output. Each entry in the array is formatted to text by
176 first converting it to the closest Python type, and then using “format” % item.
176 first converting it to the closest Python type, and then using “format” % item.
177
177
178 '''
178 '''
179
179
180 return 1
180 return 1
181
181
182
182
183 class RecordHeader(Header):
183 class RecordHeader(Header):
184
184
185 RecMgcNumber=None #0x23030001
185 RecMgcNumber=None #0x23030001
186 RecCounter= None
186 RecCounter= None
187 Off2StartNxtRec= None
187 Off2StartNxtRec= None
188 EpTimeStamp= None
188 EpTimeStamp= None
189 msCompTimeStamp= None
189 msCompTimeStamp= None
190 ExpTagName= None
190 ExpTagName= None
191 ExpComment=None
191 ExpComment=None
192 SiteLatDegrees=None
192 SiteLatDegrees=None
193 SiteLongDegrees= None
193 SiteLongDegrees= None
194 RTCgpsStatus= None
194 RTCgpsStatus= None
195 TransmitFrec= None
195 TransmitFrec= None
196 ReceiveFrec= None
196 ReceiveFrec= None
197 FirstOsciFrec= None
197 FirstOsciFrec= None
198 Polarisation= None
198 Polarisation= None
199 ReceiverFiltSett= None
199 ReceiverFiltSett= None
200 nModesInUse= None
200 nModesInUse= None
201 DualModeIndex= None
201 DualModeIndex= None
202 DualModeRange= None
202 DualModeRange= None
203 nDigChannels= None
203 nDigChannels= None
204 SampResolution= None
204 SampResolution= None
205 nRangeGatesSamp= None
205 nRangeGatesSamp= None
206 StartRangeSamp= None
206 StartRangeSamp= None
207 PRFhz= None
207 PRFhz= None
208 Integrations= None
208 Integrations= None
209 nDataPointsTrsf= None
209 nDataPointsTrsf= None
210 nReceiveBeams= None
210 nReceiveBeams= None
211 nSpectAverages= None
211 nSpectAverages= None
212 FFTwindowingInd= None
212 FFTwindowingInd= None
213 BeamAngleAzim= None
213 BeamAngleAzim= None
214 BeamAngleZen= None
214 BeamAngleZen= None
215 AntennaCoord= None
215 AntennaCoord= None
216 RecPhaseCalibr= None
216 RecPhaseCalibr= None
217 RecAmpCalibr= None
217 RecAmpCalibr= None
218 ReceiverGaindB= None
218 ReceiverGaindB= None
219
219
220 '''size = None
220 '''size = None
221 nSamples = None
221 nSamples = None
222 nProfiles = None
222 nProfiles = None
223 nChannels = None
223 nChannels = None
224 adcResolution = None
224 adcResolution = None
225 pciDioBusWidth = None'''
225 pciDioBusWidth = None'''
226
226
227 def __init__(self, RecMgcNumber=None, RecCounter= 0, Off2StartNxtRec= 0,
227 def __init__(self, RecMgcNumber=None, RecCounter= 0, Off2StartNxtRec= 0,
228 EpTimeStamp= 0, msCompTimeStamp= 0, ExpTagName= None,
228 EpTimeStamp= 0, msCompTimeStamp= 0, ExpTagName= None,
229 ExpComment=None, SiteLatDegrees=0, SiteLongDegrees= 0,
229 ExpComment=None, SiteLatDegrees=0, SiteLongDegrees= 0,
230 RTCgpsStatus= 0, TransmitFrec= 0, ReceiveFrec= 0,
230 RTCgpsStatus= 0, TransmitFrec= 0, ReceiveFrec= 0,
231 FirstOsciFrec= 0, Polarisation= 0, ReceiverFiltSett= 0,
231 FirstOsciFrec= 0, Polarisation= 0, ReceiverFiltSett= 0,
232 nModesInUse= 0, DualModeIndex= 0, DualModeRange= 0,
232 nModesInUse= 0, DualModeIndex= 0, DualModeRange= 0,
233 nDigChannels= 0, SampResolution= 0, nRangeGatesSamp= 0,
233 nDigChannels= 0, SampResolution= 0, nRangeGatesSamp= 0,
234 StartRangeSamp= 0, PRFhz= 0, Integrations= 0,
234 StartRangeSamp= 0, PRFhz= 0, Integrations= 0,
235 nDataPointsTrsf= 0, nReceiveBeams= 0, nSpectAverages= 0,
235 nDataPointsTrsf= 0, nReceiveBeams= 0, nSpectAverages= 0,
236 FFTwindowingInd= 0, BeamAngleAzim= 0, BeamAngleZen= 0,
236 FFTwindowingInd= 0, BeamAngleAzim= 0, BeamAngleZen= 0,
237 AntennaCoord= 0, RecPhaseCalibr= 0, RecAmpCalibr= 0,
237 AntennaCoord= 0, RecPhaseCalibr= 0, RecAmpCalibr= 0,
238 ReceiverGaindB= 0):
238 ReceiverGaindB= 0):
239
239
240 self.RecMgcNumber = RecMgcNumber #0x23030001
240 self.RecMgcNumber = RecMgcNumber #0x23030001
241 self.RecCounter = RecCounter
241 self.RecCounter = RecCounter
242 self.Off2StartNxtRec = Off2StartNxtRec
242 self.Off2StartNxtRec = Off2StartNxtRec
243 self.EpTimeStamp = EpTimeStamp
243 self.EpTimeStamp = EpTimeStamp
244 self.msCompTimeStamp = msCompTimeStamp
244 self.msCompTimeStamp = msCompTimeStamp
245 self.ExpTagName = ExpTagName
245 self.ExpTagName = ExpTagName
246 self.ExpComment = ExpComment
246 self.ExpComment = ExpComment
247 self.SiteLatDegrees = SiteLatDegrees
247 self.SiteLatDegrees = SiteLatDegrees
248 self.SiteLongDegrees = SiteLongDegrees
248 self.SiteLongDegrees = SiteLongDegrees
249 self.RTCgpsStatus = RTCgpsStatus
249 self.RTCgpsStatus = RTCgpsStatus
250 self.TransmitFrec = TransmitFrec
250 self.TransmitFrec = TransmitFrec
251 self.ReceiveFrec = ReceiveFrec
251 self.ReceiveFrec = ReceiveFrec
252 self.FirstOsciFrec = FirstOsciFrec
252 self.FirstOsciFrec = FirstOsciFrec
253 self.Polarisation = Polarisation
253 self.Polarisation = Polarisation
254 self.ReceiverFiltSett = ReceiverFiltSett
254 self.ReceiverFiltSett = ReceiverFiltSett
255 self.nModesInUse = nModesInUse
255 self.nModesInUse = nModesInUse
256 self.DualModeIndex = DualModeIndex
256 self.DualModeIndex = DualModeIndex
257 self.DualModeRange = DualModeRange
257 self.DualModeRange = DualModeRange
258 self.nDigChannels = nDigChannels
258 self.nDigChannels = nDigChannels
259 self.SampResolution = SampResolution
259 self.SampResolution = SampResolution
260 self.nRangeGatesSamp = nRangeGatesSamp
260 self.nRangeGatesSamp = nRangeGatesSamp
261 self.StartRangeSamp = StartRangeSamp
261 self.StartRangeSamp = StartRangeSamp
262 self.PRFhz = PRFhz
262 self.PRFhz = PRFhz
263 self.Integrations = Integrations
263 self.Integrations = Integrations
264 self.nDataPointsTrsf = nDataPointsTrsf
264 self.nDataPointsTrsf = nDataPointsTrsf
265 self.nReceiveBeams = nReceiveBeams
265 self.nReceiveBeams = nReceiveBeams
266 self.nSpectAverages = nSpectAverages
266 self.nSpectAverages = nSpectAverages
267 self.FFTwindowingInd = FFTwindowingInd
267 self.FFTwindowingInd = FFTwindowingInd
268 self.BeamAngleAzim = BeamAngleAzim
268 self.BeamAngleAzim = BeamAngleAzim
269 self.BeamAngleZen = BeamAngleZen
269 self.BeamAngleZen = BeamAngleZen
270 self.AntennaCoord = AntennaCoord
270 self.AntennaCoord = AntennaCoord
271 self.RecPhaseCalibr = RecPhaseCalibr
271 self.RecPhaseCalibr = RecPhaseCalibr
272 self.RecAmpCalibr = RecAmpCalibr
272 self.RecAmpCalibr = RecAmpCalibr
273 self.ReceiverGaindB = ReceiverGaindB
273 self.ReceiverGaindB = ReceiverGaindB
274
274
275
275
276 def read(self, fp):
276 def read(self, fp):
277
277
278 startFp = fp.tell() #The method tell() returns the current position of the file read/write pointer within the file.
278 startFp = fp.tell() #The method tell() returns the current position of the file read/write pointer within the file.
279
279
280 try:
280 try:
281 header = numpy.fromfile(fp,RECORD_STRUCTURE,1)
281 header = numpy.fromfile(fp,RECORD_STRUCTURE,1)
282 except Exception, e:
282 except Exception as e:
283 print "System Header: " + e
283 print("System Header: " + e)
284 return 0
284 return 0
285
285
286 self.RecMgcNumber = header['RecMgcNumber'][0] #0x23030001
286 self.RecMgcNumber = header['RecMgcNumber'][0] #0x23030001
287 self.RecCounter = header['RecCounter'][0]
287 self.RecCounter = header['RecCounter'][0]
288 self.Off2StartNxtRec = header['Off2StartNxtRec'][0]
288 self.Off2StartNxtRec = header['Off2StartNxtRec'][0]
289 self.EpTimeStamp = header['EpTimeStamp'][0]
289 self.EpTimeStamp = header['EpTimeStamp'][0]
290 self.msCompTimeStamp = header['msCompTimeStamp'][0]
290 self.msCompTimeStamp = header['msCompTimeStamp'][0]
291 self.ExpTagName = header['ExpTagName'][0]
291 self.ExpTagName = header['ExpTagName'][0]
292 self.ExpComment = header['ExpComment'][0]
292 self.ExpComment = header['ExpComment'][0]
293 self.SiteLatDegrees = header['SiteLatDegrees'][0]
293 self.SiteLatDegrees = header['SiteLatDegrees'][0]
294 self.SiteLongDegrees = header['SiteLongDegrees'][0]
294 self.SiteLongDegrees = header['SiteLongDegrees'][0]
295 self.RTCgpsStatus = header['RTCgpsStatus'][0]
295 self.RTCgpsStatus = header['RTCgpsStatus'][0]
296 self.TransmitFrec = header['TransmitFrec'][0]
296 self.TransmitFrec = header['TransmitFrec'][0]
297 self.ReceiveFrec = header['ReceiveFrec'][0]
297 self.ReceiveFrec = header['ReceiveFrec'][0]
298 self.FirstOsciFrec = header['FirstOsciFrec'][0]
298 self.FirstOsciFrec = header['FirstOsciFrec'][0]
299 self.Polarisation = header['Polarisation'][0]
299 self.Polarisation = header['Polarisation'][0]
300 self.ReceiverFiltSett = header['ReceiverFiltSett'][0]
300 self.ReceiverFiltSett = header['ReceiverFiltSett'][0]
301 self.nModesInUse = header['nModesInUse'][0]
301 self.nModesInUse = header['nModesInUse'][0]
302 self.DualModeIndex = header['DualModeIndex'][0]
302 self.DualModeIndex = header['DualModeIndex'][0]
303 self.DualModeRange = header['DualModeRange'][0]
303 self.DualModeRange = header['DualModeRange'][0]
304 self.nDigChannels = header['nDigChannels'][0]
304 self.nDigChannels = header['nDigChannels'][0]
305 self.SampResolution = header['SampResolution'][0]
305 self.SampResolution = header['SampResolution'][0]
306 self.nRangeGatesSamp = header['nRangeGatesSamp'][0]
306 self.nRangeGatesSamp = header['nRangeGatesSamp'][0]
307 self.StartRangeSamp = header['StartRangeSamp'][0]
307 self.StartRangeSamp = header['StartRangeSamp'][0]
308 self.PRFhz = header['PRFhz'][0]
308 self.PRFhz = header['PRFhz'][0]
309 self.Integrations = header['Integrations'][0]
309 self.Integrations = header['Integrations'][0]
310 self.nDataPointsTrsf = header['nDataPointsTrsf'][0]
310 self.nDataPointsTrsf = header['nDataPointsTrsf'][0]
311 self.nReceiveBeams = header['nReceiveBeams'][0]
311 self.nReceiveBeams = header['nReceiveBeams'][0]
312 self.nSpectAverages = header['nSpectAverages'][0]
312 self.nSpectAverages = header['nSpectAverages'][0]
313 self.FFTwindowingInd = header['FFTwindowingInd'][0]
313 self.FFTwindowingInd = header['FFTwindowingInd'][0]
314 self.BeamAngleAzim = header['BeamAngleAzim'][0]
314 self.BeamAngleAzim = header['BeamAngleAzim'][0]
315 self.BeamAngleZen = header['BeamAngleZen'][0]
315 self.BeamAngleZen = header['BeamAngleZen'][0]
316 self.AntennaCoord = header['AntennaCoord'][0]
316 self.AntennaCoord = header['AntennaCoord'][0]
317 self.RecPhaseCalibr = header['RecPhaseCalibr'][0]
317 self.RecPhaseCalibr = header['RecPhaseCalibr'][0]
318 self.RecAmpCalibr = header['RecAmpCalibr'][0]
318 self.RecAmpCalibr = header['RecAmpCalibr'][0]
319 self.ReceiverGaindB = header['ReceiverGaindB'][0]
319 self.ReceiverGaindB = header['ReceiverGaindB'][0]
320
320
321 Self.size = 180+20*3
321 Self.size = 180+20*3
322
322
323 endFp = self.size + startFp
323 endFp = self.size + startFp
324
324
325 if fp.tell() > endFp:
325 if fp.tell() > endFp:
326 sys.stderr.write("Warning %s: Size value read from System Header is lower than it has to be\n" %fp.name)
326 sys.stderr.write("Warning %s: Size value read from System Header is lower than it has to be\n" %fp.name)
327 return 0
327 return 0
328
328
329 if fp.tell() < endFp:
329 if fp.tell() < endFp:
330 sys.stderr.write("Warning %s: Size value read from System Header size is greater than it has to be\n" %fp.name)
330 sys.stderr.write("Warning %s: Size value read from System Header size is greater than it has to be\n" %fp.name)
331 return 0
331 return 0
332
332
333 return 1
333 return 1
334
334
335 def write(self, fp):
335 def write(self, fp):
336
336
337 headerTuple = (self.RecMgcNumber,
337 headerTuple = (self.RecMgcNumber,
338 self.RecCounter,
338 self.RecCounter,
339 self.Off2StartNxtRec,
339 self.Off2StartNxtRec,
340 self.EpTimeStamp,
340 self.EpTimeStamp,
341 self.msCompTimeStamp,
341 self.msCompTimeStamp,
342 self.ExpTagName,
342 self.ExpTagName,
343 self.ExpComment,
343 self.ExpComment,
344 self.SiteLatDegrees,
344 self.SiteLatDegrees,
345 self.SiteLongDegrees,
345 self.SiteLongDegrees,
346 self.RTCgpsStatus,
346 self.RTCgpsStatus,
347 self.TransmitFrec,
347 self.TransmitFrec,
348 self.ReceiveFrec,
348 self.ReceiveFrec,
349 self.FirstOsciFrec,
349 self.FirstOsciFrec,
350 self.Polarisation,
350 self.Polarisation,
351 self.ReceiverFiltSett,
351 self.ReceiverFiltSett,
352 self.nModesInUse,
352 self.nModesInUse,
353 self.DualModeIndex,
353 self.DualModeIndex,
354 self.DualModeRange,
354 self.DualModeRange,
355 self.nDigChannels,
355 self.nDigChannels,
356 self.SampResolution,
356 self.SampResolution,
357 self.nRangeGatesSamp,
357 self.nRangeGatesSamp,
358 self.StartRangeSamp,
358 self.StartRangeSamp,
359 self.PRFhz,
359 self.PRFhz,
360 self.Integrations,
360 self.Integrations,
361 self.nDataPointsTrsf,
361 self.nDataPointsTrsf,
362 self.nReceiveBeams,
362 self.nReceiveBeams,
363 self.nSpectAverages,
363 self.nSpectAverages,
364 self.FFTwindowingInd,
364 self.FFTwindowingInd,
365 self.BeamAngleAzim,
365 self.BeamAngleAzim,
366 self.BeamAngleZen,
366 self.BeamAngleZen,
367 self.AntennaCoord,
367 self.AntennaCoord,
368 self.RecPhaseCalibr,
368 self.RecPhaseCalibr,
369 self.RecAmpCalibr,
369 self.RecAmpCalibr,
370 self.ReceiverGaindB)
370 self.ReceiverGaindB)
371
371
372 # self.size,self.nSamples,
372 # self.size,self.nSamples,
373 # self.nProfiles,
373 # self.nProfiles,
374 # self.nChannels,
374 # self.nChannels,
375 # self.adcResolution,
375 # self.adcResolution,
376 # self.pciDioBusWidth
376 # self.pciDioBusWidth
377
377
378 header = numpy.array(headerTuple,RECORD_STRUCTURE)
378 header = numpy.array(headerTuple,RECORD_STRUCTURE)
379 header.tofile(fp)
379 header.tofile(fp)
380
380
381 return 1
381 return 1
382
382
383
383
384 def get_dtype_index(numpy_dtype):
384 def get_dtype_index(numpy_dtype):
385
385
386 index = None
386 index = None
387
387
388 for i in range(len(NUMPY_DTYPE_LIST)):
388 for i in range(len(NUMPY_DTYPE_LIST)):
389 if numpy_dtype == NUMPY_DTYPE_LIST[i]:
389 if numpy_dtype == NUMPY_DTYPE_LIST[i]:
390 index = i
390 index = i
391 break
391 break
392
392
393 return index
393 return index
394
394
395 def get_numpy_dtype(index):
395 def get_numpy_dtype(index):
396
396
397 #dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
397 #dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
398
398
399 return NUMPY_DTYPE_LIST[index]
399 return NUMPY_DTYPE_LIST[index]
400
400
401
401
402 def get_dtype_width(index):
402 def get_dtype_width(index):
403
403
404 return DTYPE_WIDTH[index] No newline at end of file
404 return DTYPE_WIDTH[index]
@@ -1,3 +1,3
1 from jrodata import *
1 from .jrodata import *
2 from jroheaderIO import *
2 from .jroheaderIO import *
3 from jroamisr import * No newline at end of file
3 from .jroamisr import * No newline at end of file
@@ -1,90 +1,90
1 import numpy
1 import numpy
2 import copy
2 import copy
3
3
4 class Beam:
4 class Beam:
5 def __init__(self):
5 def __init__(self):
6 self.codeList = []
6 self.codeList = []
7 self.azimuthList = []
7 self.azimuthList = []
8 self.zenithList = []
8 self.zenithList = []
9
9
10
10
11 class AMISR:
11 class AMISR:
12 def __init__(self):
12 def __init__(self):
13 self.flagNoData = True
13 self.flagNoData = True
14 self.data = None
14 self.data = None
15 self.utctime = None
15 self.utctime = None
16 self.type = "AMISR"
16 self.type = "AMISR"
17
17
18 #propiedades para compatibilidad con Voltages
18 #propiedades para compatibilidad con Voltages
19 self.timeZone = 0#timezone like jroheader, difference in minutes between UTC and localtime
19 self.timeZone = 0#timezone like jroheader, difference in minutes between UTC and localtime
20 self.dstFlag = 0#self.dataIn.dstFlag
20 self.dstFlag = 0#self.dataIn.dstFlag
21 self.errorCount = 0#self.dataIn.errorCount
21 self.errorCount = 0#self.dataIn.errorCount
22 self.useLocalTime = True#self.dataIn.useLocalTime
22 self.useLocalTime = True#self.dataIn.useLocalTime
23
23
24 self.radarControllerHeaderObj = None#self.dataIn.radarControllerHeaderObj.copy()
24 self.radarControllerHeaderObj = None#self.dataIn.radarControllerHeaderObj.copy()
25 self.systemHeaderObj = None#self.dataIn.systemHeaderObj.copy()
25 self.systemHeaderObj = None#self.dataIn.systemHeaderObj.copy()
26 self.channelList = [0]#self.dataIn.channelList esto solo aplica para el caso de AMISR
26 self.channelList = [0]#self.dataIn.channelList esto solo aplica para el caso de AMISR
27 self.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
27 self.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
28
28
29 self.flagDiscontinuousBlock = None#self.dataIn.flagDiscontinuousBlock
29 self.flagDiscontinuousBlock = None#self.dataIn.flagDiscontinuousBlock
30 #self.utctime = #self.firstdatatime
30 #self.utctime = #self.firstdatatime
31 self.flagDecodeData = None#self.dataIn.flagDecodeData #asumo q la data esta decodificada
31 self.flagDecodeData = None#self.dataIn.flagDecodeData #asumo q la data esta decodificada
32 self.flagDeflipData = None#self.dataIn.flagDeflipData #asumo q la data esta sin flip
32 self.flagDeflipData = None#self.dataIn.flagDeflipData #asumo q la data esta sin flip
33
33
34 self.nCohInt = 1#self.dataIn.nCohInt
34 self.nCohInt = 1#self.dataIn.nCohInt
35 self.nIncohInt = 1
35 self.nIncohInt = 1
36 self.ippSeconds = None#self.dataIn.ippSeconds, segun el filename/Setup/Tufile
36 self.ippSeconds = None#self.dataIn.ippSeconds, segun el filename/Setup/Tufile
37 self.windowOfFilter = None#self.dataIn.windowOfFilter
37 self.windowOfFilter = None#self.dataIn.windowOfFilter
38
38
39 self.timeInterval = None#self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt
39 self.timeInterval = None#self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt
40 self.frequency = None#self.dataIn.frequency
40 self.frequency = None#self.dataIn.frequency
41 self.realtime = 0#self.dataIn.realtime
41 self.realtime = 0#self.dataIn.realtime
42
42
43 #actualizar en la lectura de datos
43 #actualizar en la lectura de datos
44 self.heightList = None#self.dataIn.heightList
44 self.heightList = None#self.dataIn.heightList
45 self.nProfiles = None#Number of samples or nFFTPoints
45 self.nProfiles = None#Number of samples or nFFTPoints
46 self.nRecords = None
46 self.nRecords = None
47 self.nBeams = None
47 self.nBeams = None
48 self.nBaud = None#self.dataIn.nBaud
48 self.nBaud = None#self.dataIn.nBaud
49 self.nCode = None#self.dataIn.nCode
49 self.nCode = None#self.dataIn.nCode
50 self.code = None#self.dataIn.code
50 self.code = None#self.dataIn.code
51
51
52 #consideracion para los Beams
52 #consideracion para los Beams
53 self.beamCodeDict = None
53 self.beamCodeDict = None
54 self.beamRangeDict = None
54 self.beamRangeDict = None
55 self.beamcode = None
55 self.beamcode = None
56 self.azimuth = None
56 self.azimuth = None
57 self.zenith = None
57 self.zenith = None
58 self.gain = None
58 self.gain = None
59
59
60 self.npulseByFrame = None
60 self.npulseByFrame = None
61
61
62 self.profileIndex = None
62 self.profileIndex = None
63
63
64 self.beam = Beam()
64 self.beam = Beam()
65
65
66 def copy(self, inputObj=None):
66 def copy(self, inputObj=None):
67
67
68 if inputObj is None:
68 if inputObj is None:
69 return copy.deepcopy(self)
69 return copy.deepcopy(self)
70
70
71 for key in inputObj.__dict__.keys():
71 for key in list(inputObj.__dict__.keys()):
72 self.__dict__[key] = inputObj.__dict__[key]
72 self.__dict__[key] = inputObj.__dict__[key]
73
73
74 def getNHeights(self):
74 def getNHeights(self):
75
75
76 return len(self.heightList)
76 return len(self.heightList)
77
77
78
78
79 def isEmpty(self):
79 def isEmpty(self):
80
80
81 return self.flagNoData
81 return self.flagNoData
82
82
83 def getTimeInterval(self):
83 def getTimeInterval(self):
84
84
85 timeInterval = self.ippSeconds * self.nCohInt
85 timeInterval = self.ippSeconds * self.nCohInt
86
86
87 return timeInterval
87 return timeInterval
88
88
89 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
89 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
90 nHeights = property(getNHeights, "I'm the 'nHeights' property.") No newline at end of file
90 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
@@ -1,1251 +1,1251
1 '''
1 '''
2
2
3 $Author: murco $
3 $Author: murco $
4 $Id: JROData.py 173 2012-11-20 15:06:21Z murco $
4 $Id: JROData.py 173 2012-11-20 15:06:21Z murco $
5 '''
5 '''
6
6
7 import copy
7 import copy
8 import numpy
8 import numpy
9 import datetime
9 import datetime
10
10
11 from jroheaderIO import SystemHeader, RadarControllerHeader
11 from .jroheaderIO import SystemHeader, RadarControllerHeader
12 from schainpy import cSchain
12 # from schainpy import cSchain
13
13
14
14
15 def getNumpyDtype(dataTypeCode):
15 def getNumpyDtype(dataTypeCode):
16
16
17 if dataTypeCode == 0:
17 if dataTypeCode == 0:
18 numpyDtype = numpy.dtype([('real', '<i1'), ('imag', '<i1')])
18 numpyDtype = numpy.dtype([('real', '<i1'), ('imag', '<i1')])
19 elif dataTypeCode == 1:
19 elif dataTypeCode == 1:
20 numpyDtype = numpy.dtype([('real', '<i2'), ('imag', '<i2')])
20 numpyDtype = numpy.dtype([('real', '<i2'), ('imag', '<i2')])
21 elif dataTypeCode == 2:
21 elif dataTypeCode == 2:
22 numpyDtype = numpy.dtype([('real', '<i4'), ('imag', '<i4')])
22 numpyDtype = numpy.dtype([('real', '<i4'), ('imag', '<i4')])
23 elif dataTypeCode == 3:
23 elif dataTypeCode == 3:
24 numpyDtype = numpy.dtype([('real', '<i8'), ('imag', '<i8')])
24 numpyDtype = numpy.dtype([('real', '<i8'), ('imag', '<i8')])
25 elif dataTypeCode == 4:
25 elif dataTypeCode == 4:
26 numpyDtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
26 numpyDtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
27 elif dataTypeCode == 5:
27 elif dataTypeCode == 5:
28 numpyDtype = numpy.dtype([('real', '<f8'), ('imag', '<f8')])
28 numpyDtype = numpy.dtype([('real', '<f8'), ('imag', '<f8')])
29 else:
29 else:
30 raise ValueError, 'dataTypeCode was not defined'
30 raise ValueError('dataTypeCode was not defined')
31
31
32 return numpyDtype
32 return numpyDtype
33
33
34
34
35 def getDataTypeCode(numpyDtype):
35 def getDataTypeCode(numpyDtype):
36
36
37 if numpyDtype == numpy.dtype([('real', '<i1'), ('imag', '<i1')]):
37 if numpyDtype == numpy.dtype([('real', '<i1'), ('imag', '<i1')]):
38 datatype = 0
38 datatype = 0
39 elif numpyDtype == numpy.dtype([('real', '<i2'), ('imag', '<i2')]):
39 elif numpyDtype == numpy.dtype([('real', '<i2'), ('imag', '<i2')]):
40 datatype = 1
40 datatype = 1
41 elif numpyDtype == numpy.dtype([('real', '<i4'), ('imag', '<i4')]):
41 elif numpyDtype == numpy.dtype([('real', '<i4'), ('imag', '<i4')]):
42 datatype = 2
42 datatype = 2
43 elif numpyDtype == numpy.dtype([('real', '<i8'), ('imag', '<i8')]):
43 elif numpyDtype == numpy.dtype([('real', '<i8'), ('imag', '<i8')]):
44 datatype = 3
44 datatype = 3
45 elif numpyDtype == numpy.dtype([('real', '<f4'), ('imag', '<f4')]):
45 elif numpyDtype == numpy.dtype([('real', '<f4'), ('imag', '<f4')]):
46 datatype = 4
46 datatype = 4
47 elif numpyDtype == numpy.dtype([('real', '<f8'), ('imag', '<f8')]):
47 elif numpyDtype == numpy.dtype([('real', '<f8'), ('imag', '<f8')]):
48 datatype = 5
48 datatype = 5
49 else:
49 else:
50 datatype = None
50 datatype = None
51
51
52 return datatype
52 return datatype
53
53
54
54
55 def hildebrand_sekhon(data, navg):
55 def hildebrand_sekhon(data, navg):
56 """
56 """
57 This method is for the objective determination of the noise level in Doppler spectra. This
57 This method is for the objective determination of the noise level in Doppler spectra. This
58 implementation technique is based on the fact that the standard deviation of the spectral
58 implementation technique is based on the fact that the standard deviation of the spectral
59 densities is equal to the mean spectral density for white Gaussian noise
59 densities is equal to the mean spectral density for white Gaussian noise
60
60
61 Inputs:
61 Inputs:
62 Data : heights
62 Data : heights
63 navg : numbers of averages
63 navg : numbers of averages
64
64
65 Return:
65 Return:
66 -1 : any error
66 -1 : any error
67 anoise : noise's level
67 anoise : noise's level
68 """
68 """
69
69
70 sortdata = numpy.sort(data, axis=None)
70 sortdata = numpy.sort(data, axis=None)
71 # lenOfData = len(sortdata)
71 lenOfData = len(sortdata)
72 # nums_min = lenOfData*0.2
72 nums_min = lenOfData*0.2
73 #
73
74 # if nums_min <= 5:
74 if nums_min <= 5:
75 # nums_min = 5
75 nums_min = 5
76 #
76
77 # sump = 0.
77 sump = 0.
78 #
78
79 # sumq = 0.
79 sumq = 0.
80 #
80
81 # j = 0
81 j = 0
82 #
82
83 # cont = 1
83 cont = 1
84 #
84
85 # while((cont==1)and(j<lenOfData)):
85 while((cont==1)and(j<lenOfData)):
86 #
86
87 # sump += sortdata[j]
87 sump += sortdata[j]
88 #
88
89 # sumq += sortdata[j]**2
89 sumq += sortdata[j]**2
90 #
90
91 # if j > nums_min:
91 if j > nums_min:
92 # rtest = float(j)/(j-1) + 1.0/navg
92 rtest = float(j)/(j-1) + 1.0/navg
93 # if ((sumq*j) > (rtest*sump**2)):
93 if ((sumq*j) > (rtest*sump**2)):
94 # j = j - 1
94 j = j - 1
95 # sump = sump - sortdata[j]
95 sump = sump - sortdata[j]
96 # sumq = sumq - sortdata[j]**2
96 sumq = sumq - sortdata[j]**2
97 # cont = 0
97 cont = 0
98 #
98
99 # j += 1
99 j += 1
100 #
100
101 # lnoise = sump /j
101 lnoise = sump /j
102 #
102
103 # return lnoise
103 return lnoise
104
104
105 return cSchain.hildebrand_sekhon(sortdata, navg)
105 # return cSchain.hildebrand_sekhon(sortdata, navg)
106
106
107
107
108 class Beam:
108 class Beam:
109
109
110 def __init__(self):
110 def __init__(self):
111 self.codeList = []
111 self.codeList = []
112 self.azimuthList = []
112 self.azimuthList = []
113 self.zenithList = []
113 self.zenithList = []
114
114
115
115
116 class GenericData(object):
116 class GenericData(object):
117
117
118 flagNoData = True
118 flagNoData = True
119
119
120 def copy(self, inputObj=None):
120 def copy(self, inputObj=None):
121
121
122 if inputObj == None:
122 if inputObj == None:
123 return copy.deepcopy(self)
123 return copy.deepcopy(self)
124
124
125 for key in inputObj.__dict__.keys():
125 for key in list(inputObj.__dict__.keys()):
126
126
127 attribute = inputObj.__dict__[key]
127 attribute = inputObj.__dict__[key]
128
128
129 # If this attribute is a tuple or list
129 # If this attribute is a tuple or list
130 if type(inputObj.__dict__[key]) in (tuple, list):
130 if type(inputObj.__dict__[key]) in (tuple, list):
131 self.__dict__[key] = attribute[:]
131 self.__dict__[key] = attribute[:]
132 continue
132 continue
133
133
134 # If this attribute is another object or instance
134 # If this attribute is another object or instance
135 if hasattr(attribute, '__dict__'):
135 if hasattr(attribute, '__dict__'):
136 self.__dict__[key] = attribute.copy()
136 self.__dict__[key] = attribute.copy()
137 continue
137 continue
138
138
139 self.__dict__[key] = inputObj.__dict__[key]
139 self.__dict__[key] = inputObj.__dict__[key]
140
140
141 def deepcopy(self):
141 def deepcopy(self):
142
142
143 return copy.deepcopy(self)
143 return copy.deepcopy(self)
144
144
145 def isEmpty(self):
145 def isEmpty(self):
146
146
147 return self.flagNoData
147 return self.flagNoData
148
148
149
149
150 class JROData(GenericData):
150 class JROData(GenericData):
151
151
152 # m_BasicHeader = BasicHeader()
152 # m_BasicHeader = BasicHeader()
153 # m_ProcessingHeader = ProcessingHeader()
153 # m_ProcessingHeader = ProcessingHeader()
154
154
155 systemHeaderObj = SystemHeader()
155 systemHeaderObj = SystemHeader()
156
156
157 radarControllerHeaderObj = RadarControllerHeader()
157 radarControllerHeaderObj = RadarControllerHeader()
158
158
159 # data = None
159 # data = None
160
160
161 type = None
161 type = None
162
162
163 datatype = None # dtype but in string
163 datatype = None # dtype but in string
164
164
165 # dtype = None
165 # dtype = None
166
166
167 # nChannels = None
167 # nChannels = None
168
168
169 # nHeights = None
169 # nHeights = None
170
170
171 nProfiles = None
171 nProfiles = None
172
172
173 heightList = None
173 heightList = None
174
174
175 channelList = None
175 channelList = None
176
176
177 flagDiscontinuousBlock = False
177 flagDiscontinuousBlock = False
178
178
179 useLocalTime = False
179 useLocalTime = False
180
180
181 utctime = None
181 utctime = None
182
182
183 timeZone = None
183 timeZone = None
184
184
185 dstFlag = None
185 dstFlag = None
186
186
187 errorCount = None
187 errorCount = None
188
188
189 blocksize = None
189 blocksize = None
190
190
191 # nCode = None
191 # nCode = None
192 #
192 #
193 # nBaud = None
193 # nBaud = None
194 #
194 #
195 # code = None
195 # code = None
196
196
197 flagDecodeData = False # asumo q la data no esta decodificada
197 flagDecodeData = False # asumo q la data no esta decodificada
198
198
199 flagDeflipData = False # asumo q la data no esta sin flip
199 flagDeflipData = False # asumo q la data no esta sin flip
200
200
201 flagShiftFFT = False
201 flagShiftFFT = False
202
202
203 # ippSeconds = None
203 # ippSeconds = None
204
204
205 # timeInterval = None
205 # timeInterval = None
206
206
207 nCohInt = None
207 nCohInt = None
208
208
209 # noise = None
209 # noise = None
210
210
211 windowOfFilter = 1
211 windowOfFilter = 1
212
212
213 # Speed of ligth
213 # Speed of ligth
214 C = 3e8
214 C = 3e8
215
215
216 frequency = 49.92e6
216 frequency = 49.92e6
217
217
218 realtime = False
218 realtime = False
219
219
220 beacon_heiIndexList = None
220 beacon_heiIndexList = None
221
221
222 last_block = None
222 last_block = None
223
223
224 blocknow = None
224 blocknow = None
225
225
226 azimuth = None
226 azimuth = None
227
227
228 zenith = None
228 zenith = None
229
229
230 beam = Beam()
230 beam = Beam()
231
231
232 profileIndex = None
232 profileIndex = None
233
233
234 def getNoise(self):
234 def getNoise(self):
235
235
236 raise NotImplementedError
236 raise NotImplementedError
237
237
238 def getNChannels(self):
238 def getNChannels(self):
239
239
240 return len(self.channelList)
240 return len(self.channelList)
241
241
242 def getChannelIndexList(self):
242 def getChannelIndexList(self):
243
243
244 return range(self.nChannels)
244 return list(range(self.nChannels))
245
245
246 def getNHeights(self):
246 def getNHeights(self):
247
247
248 return len(self.heightList)
248 return len(self.heightList)
249
249
250 def getHeiRange(self, extrapoints=0):
250 def getHeiRange(self, extrapoints=0):
251
251
252 heis = self.heightList
252 heis = self.heightList
253 # deltah = self.heightList[1] - self.heightList[0]
253 # deltah = self.heightList[1] - self.heightList[0]
254 #
254 #
255 # heis.append(self.heightList[-1])
255 # heis.append(self.heightList[-1])
256
256
257 return heis
257 return heis
258
258
259 def getDeltaH(self):
259 def getDeltaH(self):
260
260
261 delta = self.heightList[1] - self.heightList[0]
261 delta = self.heightList[1] - self.heightList[0]
262
262
263 return delta
263 return delta
264
264
265 def getltctime(self):
265 def getltctime(self):
266
266
267 if self.useLocalTime:
267 if self.useLocalTime:
268 return self.utctime - self.timeZone * 60
268 return self.utctime - self.timeZone * 60
269
269
270 return self.utctime
270 return self.utctime
271
271
272 def getDatatime(self):
272 def getDatatime(self):
273
273
274 datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime)
274 datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime)
275 return datatimeValue
275 return datatimeValue
276
276
277 def getTimeRange(self):
277 def getTimeRange(self):
278
278
279 datatime = []
279 datatime = []
280
280
281 datatime.append(self.ltctime)
281 datatime.append(self.ltctime)
282 datatime.append(self.ltctime + self.timeInterval + 1)
282 datatime.append(self.ltctime + self.timeInterval + 1)
283
283
284 datatime = numpy.array(datatime)
284 datatime = numpy.array(datatime)
285
285
286 return datatime
286 return datatime
287
287
288 def getFmaxTimeResponse(self):
288 def getFmaxTimeResponse(self):
289
289
290 period = (10**-6) * self.getDeltaH() / (0.15)
290 period = (10**-6) * self.getDeltaH() / (0.15)
291
291
292 PRF = 1. / (period * self.nCohInt)
292 PRF = 1. / (period * self.nCohInt)
293
293
294 fmax = PRF
294 fmax = PRF
295
295
296 return fmax
296 return fmax
297
297
298 def getFmax(self):
298 def getFmax(self):
299 PRF = 1. / (self.ippSeconds * self.nCohInt)
299 PRF = 1. / (self.ippSeconds * self.nCohInt)
300
300
301 fmax = PRF
301 fmax = PRF
302 return fmax
302 return fmax
303
303
304 def getVmax(self):
304 def getVmax(self):
305
305
306 _lambda = self.C / self.frequency
306 _lambda = self.C / self.frequency
307
307
308 vmax = self.getFmax() * _lambda / 2
308 vmax = self.getFmax() * _lambda / 2
309
309
310 return vmax
310 return vmax
311
311
312 def get_ippSeconds(self):
312 def get_ippSeconds(self):
313 '''
313 '''
314 '''
314 '''
315 return self.radarControllerHeaderObj.ippSeconds
315 return self.radarControllerHeaderObj.ippSeconds
316
316
317 def set_ippSeconds(self, ippSeconds):
317 def set_ippSeconds(self, ippSeconds):
318 '''
318 '''
319 '''
319 '''
320
320
321 self.radarControllerHeaderObj.ippSeconds = ippSeconds
321 self.radarControllerHeaderObj.ippSeconds = ippSeconds
322
322
323 return
323 return
324
324
325 def get_dtype(self):
325 def get_dtype(self):
326 '''
326 '''
327 '''
327 '''
328 return getNumpyDtype(self.datatype)
328 return getNumpyDtype(self.datatype)
329
329
330 def set_dtype(self, numpyDtype):
330 def set_dtype(self, numpyDtype):
331 '''
331 '''
332 '''
332 '''
333
333
334 self.datatype = getDataTypeCode(numpyDtype)
334 self.datatype = getDataTypeCode(numpyDtype)
335
335
336 def get_code(self):
336 def get_code(self):
337 '''
337 '''
338 '''
338 '''
339 return self.radarControllerHeaderObj.code
339 return self.radarControllerHeaderObj.code
340
340
341 def set_code(self, code):
341 def set_code(self, code):
342 '''
342 '''
343 '''
343 '''
344 self.radarControllerHeaderObj.code = code
344 self.radarControllerHeaderObj.code = code
345
345
346 return
346 return
347
347
348 def get_ncode(self):
348 def get_ncode(self):
349 '''
349 '''
350 '''
350 '''
351 return self.radarControllerHeaderObj.nCode
351 return self.radarControllerHeaderObj.nCode
352
352
353 def set_ncode(self, nCode):
353 def set_ncode(self, nCode):
354 '''
354 '''
355 '''
355 '''
356 self.radarControllerHeaderObj.nCode = nCode
356 self.radarControllerHeaderObj.nCode = nCode
357
357
358 return
358 return
359
359
360 def get_nbaud(self):
360 def get_nbaud(self):
361 '''
361 '''
362 '''
362 '''
363 return self.radarControllerHeaderObj.nBaud
363 return self.radarControllerHeaderObj.nBaud
364
364
365 def set_nbaud(self, nBaud):
365 def set_nbaud(self, nBaud):
366 '''
366 '''
367 '''
367 '''
368 self.radarControllerHeaderObj.nBaud = nBaud
368 self.radarControllerHeaderObj.nBaud = nBaud
369
369
370 return
370 return
371
371
372 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
372 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
373 channelIndexList = property(
373 channelIndexList = property(
374 getChannelIndexList, "I'm the 'channelIndexList' property.")
374 getChannelIndexList, "I'm the 'channelIndexList' property.")
375 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
375 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
376 #noise = property(getNoise, "I'm the 'nHeights' property.")
376 #noise = property(getNoise, "I'm the 'nHeights' property.")
377 datatime = property(getDatatime, "I'm the 'datatime' property")
377 datatime = property(getDatatime, "I'm the 'datatime' property")
378 ltctime = property(getltctime, "I'm the 'ltctime' property")
378 ltctime = property(getltctime, "I'm the 'ltctime' property")
379 ippSeconds = property(get_ippSeconds, set_ippSeconds)
379 ippSeconds = property(get_ippSeconds, set_ippSeconds)
380 dtype = property(get_dtype, set_dtype)
380 dtype = property(get_dtype, set_dtype)
381 # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
381 # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
382 code = property(get_code, set_code)
382 code = property(get_code, set_code)
383 nCode = property(get_ncode, set_ncode)
383 nCode = property(get_ncode, set_ncode)
384 nBaud = property(get_nbaud, set_nbaud)
384 nBaud = property(get_nbaud, set_nbaud)
385
385
386
386
387 class Voltage(JROData):
387 class Voltage(JROData):
388
388
389 # data es un numpy array de 2 dmensiones (canales, alturas)
389 # data es un numpy array de 2 dmensiones (canales, alturas)
390 data = None
390 data = None
391
391
392 def __init__(self):
392 def __init__(self):
393 '''
393 '''
394 Constructor
394 Constructor
395 '''
395 '''
396
396
397 self.useLocalTime = True
397 self.useLocalTime = True
398
398
399 self.radarControllerHeaderObj = RadarControllerHeader()
399 self.radarControllerHeaderObj = RadarControllerHeader()
400
400
401 self.systemHeaderObj = SystemHeader()
401 self.systemHeaderObj = SystemHeader()
402
402
403 self.type = "Voltage"
403 self.type = "Voltage"
404
404
405 self.data = None
405 self.data = None
406
406
407 # self.dtype = None
407 # self.dtype = None
408
408
409 # self.nChannels = 0
409 # self.nChannels = 0
410
410
411 # self.nHeights = 0
411 # self.nHeights = 0
412
412
413 self.nProfiles = None
413 self.nProfiles = None
414
414
415 self.heightList = None
415 self.heightList = None
416
416
417 self.channelList = None
417 self.channelList = None
418
418
419 # self.channelIndexList = None
419 # self.channelIndexList = None
420
420
421 self.flagNoData = True
421 self.flagNoData = True
422
422
423 self.flagDiscontinuousBlock = False
423 self.flagDiscontinuousBlock = False
424
424
425 self.utctime = None
425 self.utctime = None
426
426
427 self.timeZone = None
427 self.timeZone = None
428
428
429 self.dstFlag = None
429 self.dstFlag = None
430
430
431 self.errorCount = None
431 self.errorCount = None
432
432
433 self.nCohInt = None
433 self.nCohInt = None
434
434
435 self.blocksize = None
435 self.blocksize = None
436
436
437 self.flagDecodeData = False # asumo q la data no esta decodificada
437 self.flagDecodeData = False # asumo q la data no esta decodificada
438
438
439 self.flagDeflipData = False # asumo q la data no esta sin flip
439 self.flagDeflipData = False # asumo q la data no esta sin flip
440
440
441 self.flagShiftFFT = False
441 self.flagShiftFFT = False
442
442
443 self.flagDataAsBlock = False # Asumo que la data es leida perfil a perfil
443 self.flagDataAsBlock = False # Asumo que la data es leida perfil a perfil
444
444
445 self.profileIndex = 0
445 self.profileIndex = 0
446
446
447 def getNoisebyHildebrand(self, channel=None):
447 def getNoisebyHildebrand(self, channel=None):
448 """
448 """
449 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
449 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
450
450
451 Return:
451 Return:
452 noiselevel
452 noiselevel
453 """
453 """
454
454
455 if channel != None:
455 if channel != None:
456 data = self.data[channel]
456 data = self.data[channel]
457 nChannels = 1
457 nChannels = 1
458 else:
458 else:
459 data = self.data
459 data = self.data
460 nChannels = self.nChannels
460 nChannels = self.nChannels
461
461
462 noise = numpy.zeros(nChannels)
462 noise = numpy.zeros(nChannels)
463 power = data * numpy.conjugate(data)
463 power = data * numpy.conjugate(data)
464
464
465 for thisChannel in range(nChannels):
465 for thisChannel in range(nChannels):
466 if nChannels == 1:
466 if nChannels == 1:
467 daux = power[:].real
467 daux = power[:].real
468 else:
468 else:
469 daux = power[thisChannel, :].real
469 daux = power[thisChannel, :].real
470 noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt)
470 noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt)
471
471
472 return noise
472 return noise
473
473
474 def getNoise(self, type=1, channel=None):
474 def getNoise(self, type=1, channel=None):
475
475
476 if type == 1:
476 if type == 1:
477 noise = self.getNoisebyHildebrand(channel)
477 noise = self.getNoisebyHildebrand(channel)
478
478
479 return noise
479 return noise
480
480
481 def getPower(self, channel=None):
481 def getPower(self, channel=None):
482
482
483 if channel != None:
483 if channel != None:
484 data = self.data[channel]
484 data = self.data[channel]
485 else:
485 else:
486 data = self.data
486 data = self.data
487
487
488 power = data * numpy.conjugate(data)
488 power = data * numpy.conjugate(data)
489 powerdB = 10 * numpy.log10(power.real)
489 powerdB = 10 * numpy.log10(power.real)
490 powerdB = numpy.squeeze(powerdB)
490 powerdB = numpy.squeeze(powerdB)
491
491
492 return powerdB
492 return powerdB
493
493
494 def getTimeInterval(self):
494 def getTimeInterval(self):
495
495
496 timeInterval = self.ippSeconds * self.nCohInt
496 timeInterval = self.ippSeconds * self.nCohInt
497
497
498 return timeInterval
498 return timeInterval
499
499
500 noise = property(getNoise, "I'm the 'nHeights' property.")
500 noise = property(getNoise, "I'm the 'nHeights' property.")
501 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
501 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
502
502
503
503
504 class Spectra(JROData):
504 class Spectra(JROData):
505
505
506 # data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas)
506 # data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas)
507 data_spc = None
507 data_spc = None
508
508
509 # data cspc es un numpy array de 2 dmensiones (canales, pares, alturas)
509 # data cspc es un numpy array de 2 dmensiones (canales, pares, alturas)
510 data_cspc = None
510 data_cspc = None
511
511
512 # data dc es un numpy array de 2 dmensiones (canales, alturas)
512 # data dc es un numpy array de 2 dmensiones (canales, alturas)
513 data_dc = None
513 data_dc = None
514
514
515 # data power
515 # data power
516 data_pwr = None
516 data_pwr = None
517
517
518 nFFTPoints = None
518 nFFTPoints = None
519
519
520 # nPairs = None
520 # nPairs = None
521
521
522 pairsList = None
522 pairsList = None
523
523
524 nIncohInt = None
524 nIncohInt = None
525
525
526 wavelength = None # Necesario para cacular el rango de velocidad desde la frecuencia
526 wavelength = None # Necesario para cacular el rango de velocidad desde la frecuencia
527
527
528 nCohInt = None # se requiere para determinar el valor de timeInterval
528 nCohInt = None # se requiere para determinar el valor de timeInterval
529
529
530 ippFactor = None
530 ippFactor = None
531
531
532 profileIndex = 0
532 profileIndex = 0
533
533
534 plotting = "spectra"
534 plotting = "spectra"
535
535
536 def __init__(self):
536 def __init__(self):
537 '''
537 '''
538 Constructor
538 Constructor
539 '''
539 '''
540
540
541 self.useLocalTime = True
541 self.useLocalTime = True
542
542
543 self.radarControllerHeaderObj = RadarControllerHeader()
543 self.radarControllerHeaderObj = RadarControllerHeader()
544
544
545 self.systemHeaderObj = SystemHeader()
545 self.systemHeaderObj = SystemHeader()
546
546
547 self.type = "Spectra"
547 self.type = "Spectra"
548
548
549 # self.data = None
549 # self.data = None
550
550
551 # self.dtype = None
551 # self.dtype = None
552
552
553 # self.nChannels = 0
553 # self.nChannels = 0
554
554
555 # self.nHeights = 0
555 # self.nHeights = 0
556
556
557 self.nProfiles = None
557 self.nProfiles = None
558
558
559 self.heightList = None
559 self.heightList = None
560
560
561 self.channelList = None
561 self.channelList = None
562
562
563 # self.channelIndexList = None
563 # self.channelIndexList = None
564
564
565 self.pairsList = None
565 self.pairsList = None
566
566
567 self.flagNoData = True
567 self.flagNoData = True
568
568
569 self.flagDiscontinuousBlock = False
569 self.flagDiscontinuousBlock = False
570
570
571 self.utctime = None
571 self.utctime = None
572
572
573 self.nCohInt = None
573 self.nCohInt = None
574
574
575 self.nIncohInt = None
575 self.nIncohInt = None
576
576
577 self.blocksize = None
577 self.blocksize = None
578
578
579 self.nFFTPoints = None
579 self.nFFTPoints = None
580
580
581 self.wavelength = None
581 self.wavelength = None
582
582
583 self.flagDecodeData = False # asumo q la data no esta decodificada
583 self.flagDecodeData = False # asumo q la data no esta decodificada
584
584
585 self.flagDeflipData = False # asumo q la data no esta sin flip
585 self.flagDeflipData = False # asumo q la data no esta sin flip
586
586
587 self.flagShiftFFT = False
587 self.flagShiftFFT = False
588
588
589 self.ippFactor = 1
589 self.ippFactor = 1
590
590
591 #self.noise = None
591 #self.noise = None
592
592
593 self.beacon_heiIndexList = []
593 self.beacon_heiIndexList = []
594
594
595 self.noise_estimation = None
595 self.noise_estimation = None
596
596
597 def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
597 def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
598 """
598 """
599 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
599 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
600
600
601 Return:
601 Return:
602 noiselevel
602 noiselevel
603 """
603 """
604
604
605 noise = numpy.zeros(self.nChannels)
605 noise = numpy.zeros(self.nChannels)
606
606
607 for channel in range(self.nChannels):
607 for channel in range(self.nChannels):
608 daux = self.data_spc[channel,
608 daux = self.data_spc[channel,
609 xmin_index:xmax_index, ymin_index:ymax_index]
609 xmin_index:xmax_index, ymin_index:ymax_index]
610 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
610 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
611
611
612 return noise
612 return noise
613
613
614 def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
614 def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
615
615
616 if self.noise_estimation is not None:
616 if self.noise_estimation is not None:
617 # this was estimated by getNoise Operation defined in jroproc_spectra.py
617 # this was estimated by getNoise Operation defined in jroproc_spectra.py
618 return self.noise_estimation
618 return self.noise_estimation
619 else:
619 else:
620 noise = self.getNoisebyHildebrand(
620 noise = self.getNoisebyHildebrand(
621 xmin_index, xmax_index, ymin_index, ymax_index)
621 xmin_index, xmax_index, ymin_index, ymax_index)
622 return noise
622 return noise
623
623
624 def getFreqRangeTimeResponse(self, extrapoints=0):
624 def getFreqRangeTimeResponse(self, extrapoints=0):
625
625
626 deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints * self.ippFactor)
626 deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints * self.ippFactor)
627 freqrange = deltafreq * \
627 freqrange = deltafreq * \
628 (numpy.arange(self.nFFTPoints + extrapoints) -
628 (numpy.arange(self.nFFTPoints + extrapoints) -
629 self.nFFTPoints / 2.) - deltafreq / 2
629 self.nFFTPoints / 2.) - deltafreq / 2
630
630
631 return freqrange
631 return freqrange
632
632
633 def getAcfRange(self, extrapoints=0):
633 def getAcfRange(self, extrapoints=0):
634
634
635 deltafreq = 10. / (self.getFmax() / (self.nFFTPoints * self.ippFactor))
635 deltafreq = 10. / (self.getFmax() / (self.nFFTPoints * self.ippFactor))
636 freqrange = deltafreq * \
636 freqrange = deltafreq * \
637 (numpy.arange(self.nFFTPoints + extrapoints) -
637 (numpy.arange(self.nFFTPoints + extrapoints) -
638 self.nFFTPoints / 2.) - deltafreq / 2
638 self.nFFTPoints / 2.) - deltafreq / 2
639
639
640 return freqrange
640 return freqrange
641
641
642 def getFreqRange(self, extrapoints=0):
642 def getFreqRange(self, extrapoints=0):
643
643
644 deltafreq = self.getFmax() / (self.nFFTPoints * self.ippFactor)
644 deltafreq = self.getFmax() / (self.nFFTPoints * self.ippFactor)
645 freqrange = deltafreq * \
645 freqrange = deltafreq * \
646 (numpy.arange(self.nFFTPoints + extrapoints) -
646 (numpy.arange(self.nFFTPoints + extrapoints) -
647 self.nFFTPoints / 2.) - deltafreq / 2
647 self.nFFTPoints / 2.) - deltafreq / 2
648
648
649 return freqrange
649 return freqrange
650
650
651 def getVelRange(self, extrapoints=0):
651 def getVelRange(self, extrapoints=0):
652
652
653 deltav = self.getVmax() / (self.nFFTPoints * self.ippFactor)
653 deltav = self.getVmax() / (self.nFFTPoints * self.ippFactor)
654 velrange = deltav * (numpy.arange(self.nFFTPoints +
654 velrange = deltav * (numpy.arange(self.nFFTPoints +
655 extrapoints) - self.nFFTPoints / 2.) # - deltav/2
655 extrapoints) - self.nFFTPoints / 2.) # - deltav/2
656
656
657 return velrange
657 return velrange
658
658
659 def getNPairs(self):
659 def getNPairs(self):
660
660
661 return len(self.pairsList)
661 return len(self.pairsList)
662
662
663 def getPairsIndexList(self):
663 def getPairsIndexList(self):
664
664
665 return range(self.nPairs)
665 return list(range(self.nPairs))
666
666
667 def getNormFactor(self):
667 def getNormFactor(self):
668
668
669 pwcode = 1
669 pwcode = 1
670
670
671 if self.flagDecodeData:
671 if self.flagDecodeData:
672 pwcode = numpy.sum(self.code[0]**2)
672 pwcode = numpy.sum(self.code[0]**2)
673 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
673 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
674 normFactor = self.nProfiles * self.nIncohInt * \
674 normFactor = self.nProfiles * self.nIncohInt * \
675 self.nCohInt * pwcode * self.windowOfFilter
675 self.nCohInt * pwcode * self.windowOfFilter
676
676
677 return normFactor
677 return normFactor
678
678
679 def getFlagCspc(self):
679 def getFlagCspc(self):
680
680
681 if self.data_cspc is None:
681 if self.data_cspc is None:
682 return True
682 return True
683
683
684 return False
684 return False
685
685
686 def getFlagDc(self):
686 def getFlagDc(self):
687
687
688 if self.data_dc is None:
688 if self.data_dc is None:
689 return True
689 return True
690
690
691 return False
691 return False
692
692
693 def getTimeInterval(self):
693 def getTimeInterval(self):
694
694
695 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles * self.ippFactor
695 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles * self.ippFactor
696
696
697 return timeInterval
697 return timeInterval
698
698
699 def getPower(self):
699 def getPower(self):
700
700
701 factor = self.normFactor
701 factor = self.normFactor
702 z = self.data_spc / factor
702 z = self.data_spc / factor
703 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
703 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
704 avg = numpy.average(z, axis=1)
704 avg = numpy.average(z, axis=1)
705
705
706 return 10 * numpy.log10(avg)
706 return 10 * numpy.log10(avg)
707
707
708 def getCoherence(self, pairsList=None, phase=False):
708 def getCoherence(self, pairsList=None, phase=False):
709
709
710 z = []
710 z = []
711 if pairsList is None:
711 if pairsList is None:
712 pairsIndexList = self.pairsIndexList
712 pairsIndexList = self.pairsIndexList
713 else:
713 else:
714 pairsIndexList = []
714 pairsIndexList = []
715 for pair in pairsList:
715 for pair in pairsList:
716 if pair not in self.pairsList:
716 if pair not in self.pairsList:
717 raise ValueError, "Pair %s is not in dataOut.pairsList" % (
717 raise ValueError("Pair %s is not in dataOut.pairsList" % (
718 pair)
718 pair))
719 pairsIndexList.append(self.pairsList.index(pair))
719 pairsIndexList.append(self.pairsList.index(pair))
720 for i in range(len(pairsIndexList)):
720 for i in range(len(pairsIndexList)):
721 pair = self.pairsList[pairsIndexList[i]]
721 pair = self.pairsList[pairsIndexList[i]]
722 ccf = numpy.average(
722 ccf = numpy.average(
723 self.data_cspc[pairsIndexList[i], :, :], axis=0)
723 self.data_cspc[pairsIndexList[i], :, :], axis=0)
724 powa = numpy.average(self.data_spc[pair[0], :, :], axis=0)
724 powa = numpy.average(self.data_spc[pair[0], :, :], axis=0)
725 powb = numpy.average(self.data_spc[pair[1], :, :], axis=0)
725 powb = numpy.average(self.data_spc[pair[1], :, :], axis=0)
726 avgcoherenceComplex = ccf / numpy.sqrt(powa * powb)
726 avgcoherenceComplex = ccf / numpy.sqrt(powa * powb)
727 if phase:
727 if phase:
728 data = numpy.arctan2(avgcoherenceComplex.imag,
728 data = numpy.arctan2(avgcoherenceComplex.imag,
729 avgcoherenceComplex.real) * 180 / numpy.pi
729 avgcoherenceComplex.real) * 180 / numpy.pi
730 else:
730 else:
731 data = numpy.abs(avgcoherenceComplex)
731 data = numpy.abs(avgcoherenceComplex)
732
732
733 z.append(data)
733 z.append(data)
734
734
735 return numpy.array(z)
735 return numpy.array(z)
736
736
737 def setValue(self, value):
737 def setValue(self, value):
738
738
739 print "This property should not be initialized"
739 print("This property should not be initialized")
740
740
741 return
741 return
742
742
743 nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.")
743 nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.")
744 pairsIndexList = property(
744 pairsIndexList = property(
745 getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.")
745 getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.")
746 normFactor = property(getNormFactor, setValue,
746 normFactor = property(getNormFactor, setValue,
747 "I'm the 'getNormFactor' property.")
747 "I'm the 'getNormFactor' property.")
748 flag_cspc = property(getFlagCspc, setValue)
748 flag_cspc = property(getFlagCspc, setValue)
749 flag_dc = property(getFlagDc, setValue)
749 flag_dc = property(getFlagDc, setValue)
750 noise = property(getNoise, setValue, "I'm the 'nHeights' property.")
750 noise = property(getNoise, setValue, "I'm the 'nHeights' property.")
751 timeInterval = property(getTimeInterval, setValue,
751 timeInterval = property(getTimeInterval, setValue,
752 "I'm the 'timeInterval' property")
752 "I'm the 'timeInterval' property")
753
753
754
754
755 class SpectraHeis(Spectra):
755 class SpectraHeis(Spectra):
756
756
757 data_spc = None
757 data_spc = None
758
758
759 data_cspc = None
759 data_cspc = None
760
760
761 data_dc = None
761 data_dc = None
762
762
763 nFFTPoints = None
763 nFFTPoints = None
764
764
765 # nPairs = None
765 # nPairs = None
766
766
767 pairsList = None
767 pairsList = None
768
768
769 nCohInt = None
769 nCohInt = None
770
770
771 nIncohInt = None
771 nIncohInt = None
772
772
773 def __init__(self):
773 def __init__(self):
774
774
775 self.radarControllerHeaderObj = RadarControllerHeader()
775 self.radarControllerHeaderObj = RadarControllerHeader()
776
776
777 self.systemHeaderObj = SystemHeader()
777 self.systemHeaderObj = SystemHeader()
778
778
779 self.type = "SpectraHeis"
779 self.type = "SpectraHeis"
780
780
781 # self.dtype = None
781 # self.dtype = None
782
782
783 # self.nChannels = 0
783 # self.nChannels = 0
784
784
785 # self.nHeights = 0
785 # self.nHeights = 0
786
786
787 self.nProfiles = None
787 self.nProfiles = None
788
788
789 self.heightList = None
789 self.heightList = None
790
790
791 self.channelList = None
791 self.channelList = None
792
792
793 # self.channelIndexList = None
793 # self.channelIndexList = None
794
794
795 self.flagNoData = True
795 self.flagNoData = True
796
796
797 self.flagDiscontinuousBlock = False
797 self.flagDiscontinuousBlock = False
798
798
799 # self.nPairs = 0
799 # self.nPairs = 0
800
800
801 self.utctime = None
801 self.utctime = None
802
802
803 self.blocksize = None
803 self.blocksize = None
804
804
805 self.profileIndex = 0
805 self.profileIndex = 0
806
806
807 self.nCohInt = 1
807 self.nCohInt = 1
808
808
809 self.nIncohInt = 1
809 self.nIncohInt = 1
810
810
811 def getNormFactor(self):
811 def getNormFactor(self):
812 pwcode = 1
812 pwcode = 1
813 if self.flagDecodeData:
813 if self.flagDecodeData:
814 pwcode = numpy.sum(self.code[0]**2)
814 pwcode = numpy.sum(self.code[0]**2)
815
815
816 normFactor = self.nIncohInt * self.nCohInt * pwcode
816 normFactor = self.nIncohInt * self.nCohInt * pwcode
817
817
818 return normFactor
818 return normFactor
819
819
820 def getTimeInterval(self):
820 def getTimeInterval(self):
821
821
822 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
822 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
823
823
824 return timeInterval
824 return timeInterval
825
825
826 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
826 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
827 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
827 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
828
828
829
829
830 class Fits(JROData):
830 class Fits(JROData):
831
831
832 heightList = None
832 heightList = None
833
833
834 channelList = None
834 channelList = None
835
835
836 flagNoData = True
836 flagNoData = True
837
837
838 flagDiscontinuousBlock = False
838 flagDiscontinuousBlock = False
839
839
840 useLocalTime = False
840 useLocalTime = False
841
841
842 utctime = None
842 utctime = None
843
843
844 timeZone = None
844 timeZone = None
845
845
846 # ippSeconds = None
846 # ippSeconds = None
847
847
848 # timeInterval = None
848 # timeInterval = None
849
849
850 nCohInt = None
850 nCohInt = None
851
851
852 nIncohInt = None
852 nIncohInt = None
853
853
854 noise = None
854 noise = None
855
855
856 windowOfFilter = 1
856 windowOfFilter = 1
857
857
858 # Speed of ligth
858 # Speed of ligth
859 C = 3e8
859 C = 3e8
860
860
861 frequency = 49.92e6
861 frequency = 49.92e6
862
862
863 realtime = False
863 realtime = False
864
864
865 def __init__(self):
865 def __init__(self):
866
866
867 self.type = "Fits"
867 self.type = "Fits"
868
868
869 self.nProfiles = None
869 self.nProfiles = None
870
870
871 self.heightList = None
871 self.heightList = None
872
872
873 self.channelList = None
873 self.channelList = None
874
874
875 # self.channelIndexList = None
875 # self.channelIndexList = None
876
876
877 self.flagNoData = True
877 self.flagNoData = True
878
878
879 self.utctime = None
879 self.utctime = None
880
880
881 self.nCohInt = 1
881 self.nCohInt = 1
882
882
883 self.nIncohInt = 1
883 self.nIncohInt = 1
884
884
885 self.useLocalTime = True
885 self.useLocalTime = True
886
886
887 self.profileIndex = 0
887 self.profileIndex = 0
888
888
889 # self.utctime = None
889 # self.utctime = None
890 # self.timeZone = None
890 # self.timeZone = None
891 # self.ltctime = None
891 # self.ltctime = None
892 # self.timeInterval = None
892 # self.timeInterval = None
893 # self.header = None
893 # self.header = None
894 # self.data_header = None
894 # self.data_header = None
895 # self.data = None
895 # self.data = None
896 # self.datatime = None
896 # self.datatime = None
897 # self.flagNoData = False
897 # self.flagNoData = False
898 # self.expName = ''
898 # self.expName = ''
899 # self.nChannels = None
899 # self.nChannels = None
900 # self.nSamples = None
900 # self.nSamples = None
901 # self.dataBlocksPerFile = None
901 # self.dataBlocksPerFile = None
902 # self.comments = ''
902 # self.comments = ''
903 #
903 #
904
904
905 def getltctime(self):
905 def getltctime(self):
906
906
907 if self.useLocalTime:
907 if self.useLocalTime:
908 return self.utctime - self.timeZone * 60
908 return self.utctime - self.timeZone * 60
909
909
910 return self.utctime
910 return self.utctime
911
911
912 def getDatatime(self):
912 def getDatatime(self):
913
913
914 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
914 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
915 return datatime
915 return datatime
916
916
917 def getTimeRange(self):
917 def getTimeRange(self):
918
918
919 datatime = []
919 datatime = []
920
920
921 datatime.append(self.ltctime)
921 datatime.append(self.ltctime)
922 datatime.append(self.ltctime + self.timeInterval)
922 datatime.append(self.ltctime + self.timeInterval)
923
923
924 datatime = numpy.array(datatime)
924 datatime = numpy.array(datatime)
925
925
926 return datatime
926 return datatime
927
927
928 def getHeiRange(self):
928 def getHeiRange(self):
929
929
930 heis = self.heightList
930 heis = self.heightList
931
931
932 return heis
932 return heis
933
933
934 def getNHeights(self):
934 def getNHeights(self):
935
935
936 return len(self.heightList)
936 return len(self.heightList)
937
937
938 def getNChannels(self):
938 def getNChannels(self):
939
939
940 return len(self.channelList)
940 return len(self.channelList)
941
941
942 def getChannelIndexList(self):
942 def getChannelIndexList(self):
943
943
944 return range(self.nChannels)
944 return list(range(self.nChannels))
945
945
946 def getNoise(self, type=1):
946 def getNoise(self, type=1):
947
947
948 #noise = numpy.zeros(self.nChannels)
948 #noise = numpy.zeros(self.nChannels)
949
949
950 if type == 1:
950 if type == 1:
951 noise = self.getNoisebyHildebrand()
951 noise = self.getNoisebyHildebrand()
952
952
953 if type == 2:
953 if type == 2:
954 noise = self.getNoisebySort()
954 noise = self.getNoisebySort()
955
955
956 if type == 3:
956 if type == 3:
957 noise = self.getNoisebyWindow()
957 noise = self.getNoisebyWindow()
958
958
959 return noise
959 return noise
960
960
961 def getTimeInterval(self):
961 def getTimeInterval(self):
962
962
963 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
963 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
964
964
965 return timeInterval
965 return timeInterval
966
966
967 datatime = property(getDatatime, "I'm the 'datatime' property")
967 datatime = property(getDatatime, "I'm the 'datatime' property")
968 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
968 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
969 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
969 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
970 channelIndexList = property(
970 channelIndexList = property(
971 getChannelIndexList, "I'm the 'channelIndexList' property.")
971 getChannelIndexList, "I'm the 'channelIndexList' property.")
972 noise = property(getNoise, "I'm the 'nHeights' property.")
972 noise = property(getNoise, "I'm the 'nHeights' property.")
973
973
974 ltctime = property(getltctime, "I'm the 'ltctime' property")
974 ltctime = property(getltctime, "I'm the 'ltctime' property")
975 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
975 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
976
976
977
977
978 class Correlation(JROData):
978 class Correlation(JROData):
979
979
980 noise = None
980 noise = None
981
981
982 SNR = None
982 SNR = None
983
983
984 #--------------------------------------------------
984 #--------------------------------------------------
985
985
986 mode = None
986 mode = None
987
987
988 split = False
988 split = False
989
989
990 data_cf = None
990 data_cf = None
991
991
992 lags = None
992 lags = None
993
993
994 lagRange = None
994 lagRange = None
995
995
996 pairsList = None
996 pairsList = None
997
997
998 normFactor = None
998 normFactor = None
999
999
1000 #--------------------------------------------------
1000 #--------------------------------------------------
1001
1001
1002 # calculateVelocity = None
1002 # calculateVelocity = None
1003
1003
1004 nLags = None
1004 nLags = None
1005
1005
1006 nPairs = None
1006 nPairs = None
1007
1007
1008 nAvg = None
1008 nAvg = None
1009
1009
1010 def __init__(self):
1010 def __init__(self):
1011 '''
1011 '''
1012 Constructor
1012 Constructor
1013 '''
1013 '''
1014 self.radarControllerHeaderObj = RadarControllerHeader()
1014 self.radarControllerHeaderObj = RadarControllerHeader()
1015
1015
1016 self.systemHeaderObj = SystemHeader()
1016 self.systemHeaderObj = SystemHeader()
1017
1017
1018 self.type = "Correlation"
1018 self.type = "Correlation"
1019
1019
1020 self.data = None
1020 self.data = None
1021
1021
1022 self.dtype = None
1022 self.dtype = None
1023
1023
1024 self.nProfiles = None
1024 self.nProfiles = None
1025
1025
1026 self.heightList = None
1026 self.heightList = None
1027
1027
1028 self.channelList = None
1028 self.channelList = None
1029
1029
1030 self.flagNoData = True
1030 self.flagNoData = True
1031
1031
1032 self.flagDiscontinuousBlock = False
1032 self.flagDiscontinuousBlock = False
1033
1033
1034 self.utctime = None
1034 self.utctime = None
1035
1035
1036 self.timeZone = None
1036 self.timeZone = None
1037
1037
1038 self.dstFlag = None
1038 self.dstFlag = None
1039
1039
1040 self.errorCount = None
1040 self.errorCount = None
1041
1041
1042 self.blocksize = None
1042 self.blocksize = None
1043
1043
1044 self.flagDecodeData = False # asumo q la data no esta decodificada
1044 self.flagDecodeData = False # asumo q la data no esta decodificada
1045
1045
1046 self.flagDeflipData = False # asumo q la data no esta sin flip
1046 self.flagDeflipData = False # asumo q la data no esta sin flip
1047
1047
1048 self.pairsList = None
1048 self.pairsList = None
1049
1049
1050 self.nPoints = None
1050 self.nPoints = None
1051
1051
1052 def getPairsList(self):
1052 def getPairsList(self):
1053
1053
1054 return self.pairsList
1054 return self.pairsList
1055
1055
1056 def getNoise(self, mode=2):
1056 def getNoise(self, mode=2):
1057
1057
1058 indR = numpy.where(self.lagR == 0)[0][0]
1058 indR = numpy.where(self.lagR == 0)[0][0]
1059 indT = numpy.where(self.lagT == 0)[0][0]
1059 indT = numpy.where(self.lagT == 0)[0][0]
1060
1060
1061 jspectra0 = self.data_corr[:, :, indR, :]
1061 jspectra0 = self.data_corr[:, :, indR, :]
1062 jspectra = copy.copy(jspectra0)
1062 jspectra = copy.copy(jspectra0)
1063
1063
1064 num_chan = jspectra.shape[0]
1064 num_chan = jspectra.shape[0]
1065 num_hei = jspectra.shape[2]
1065 num_hei = jspectra.shape[2]
1066
1066
1067 freq_dc = jspectra.shape[1] / 2
1067 freq_dc = jspectra.shape[1] / 2
1068 ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc
1068 ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc
1069
1069
1070 if ind_vel[0] < 0:
1070 if ind_vel[0] < 0:
1071 ind_vel[range(0, 1)] = ind_vel[range(0, 1)] + self.num_prof
1071 ind_vel[list(range(0, 1))] = ind_vel[list(range(0, 1))] + self.num_prof
1072
1072
1073 if mode == 1:
1073 if mode == 1:
1074 jspectra[:, freq_dc, :] = (
1074 jspectra[:, freq_dc, :] = (
1075 jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION
1075 jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION
1076
1076
1077 if mode == 2:
1077 if mode == 2:
1078
1078
1079 vel = numpy.array([-2, -1, 1, 2])
1079 vel = numpy.array([-2, -1, 1, 2])
1080 xx = numpy.zeros([4, 4])
1080 xx = numpy.zeros([4, 4])
1081
1081
1082 for fil in range(4):
1082 for fil in range(4):
1083 xx[fil, :] = vel[fil]**numpy.asarray(range(4))
1083 xx[fil, :] = vel[fil]**numpy.asarray(list(range(4)))
1084
1084
1085 xx_inv = numpy.linalg.inv(xx)
1085 xx_inv = numpy.linalg.inv(xx)
1086 xx_aux = xx_inv[0, :]
1086 xx_aux = xx_inv[0, :]
1087
1087
1088 for ich in range(num_chan):
1088 for ich in range(num_chan):
1089 yy = jspectra[ich, ind_vel, :]
1089 yy = jspectra[ich, ind_vel, :]
1090 jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy)
1090 jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy)
1091
1091
1092 junkid = jspectra[ich, freq_dc, :] <= 0
1092 junkid = jspectra[ich, freq_dc, :] <= 0
1093 cjunkid = sum(junkid)
1093 cjunkid = sum(junkid)
1094
1094
1095 if cjunkid.any():
1095 if cjunkid.any():
1096 jspectra[ich, freq_dc, junkid.nonzero()] = (
1096 jspectra[ich, freq_dc, junkid.nonzero()] = (
1097 jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2
1097 jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2
1098
1098
1099 noise = jspectra0[:, freq_dc, :] - jspectra[:, freq_dc, :]
1099 noise = jspectra0[:, freq_dc, :] - jspectra[:, freq_dc, :]
1100
1100
1101 return noise
1101 return noise
1102
1102
1103 def getTimeInterval(self):
1103 def getTimeInterval(self):
1104
1104
1105 timeInterval = self.ippSeconds * self.nCohInt * self.nProfiles
1105 timeInterval = self.ippSeconds * self.nCohInt * self.nProfiles
1106
1106
1107 return timeInterval
1107 return timeInterval
1108
1108
1109 def splitFunctions(self):
1109 def splitFunctions(self):
1110
1110
1111 pairsList = self.pairsList
1111 pairsList = self.pairsList
1112 ccf_pairs = []
1112 ccf_pairs = []
1113 acf_pairs = []
1113 acf_pairs = []
1114 ccf_ind = []
1114 ccf_ind = []
1115 acf_ind = []
1115 acf_ind = []
1116 for l in range(len(pairsList)):
1116 for l in range(len(pairsList)):
1117 chan0 = pairsList[l][0]
1117 chan0 = pairsList[l][0]
1118 chan1 = pairsList[l][1]
1118 chan1 = pairsList[l][1]
1119
1119
1120 # Obteniendo pares de Autocorrelacion
1120 # Obteniendo pares de Autocorrelacion
1121 if chan0 == chan1:
1121 if chan0 == chan1:
1122 acf_pairs.append(chan0)
1122 acf_pairs.append(chan0)
1123 acf_ind.append(l)
1123 acf_ind.append(l)
1124 else:
1124 else:
1125 ccf_pairs.append(pairsList[l])
1125 ccf_pairs.append(pairsList[l])
1126 ccf_ind.append(l)
1126 ccf_ind.append(l)
1127
1127
1128 data_acf = self.data_cf[acf_ind]
1128 data_acf = self.data_cf[acf_ind]
1129 data_ccf = self.data_cf[ccf_ind]
1129 data_ccf = self.data_cf[ccf_ind]
1130
1130
1131 return acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf
1131 return acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf
1132
1132
1133 def getNormFactor(self):
1133 def getNormFactor(self):
1134 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions()
1134 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions()
1135 acf_pairs = numpy.array(acf_pairs)
1135 acf_pairs = numpy.array(acf_pairs)
1136 normFactor = numpy.zeros((self.nPairs, self.nHeights))
1136 normFactor = numpy.zeros((self.nPairs, self.nHeights))
1137
1137
1138 for p in range(self.nPairs):
1138 for p in range(self.nPairs):
1139 pair = self.pairsList[p]
1139 pair = self.pairsList[p]
1140
1140
1141 ch0 = pair[0]
1141 ch0 = pair[0]
1142 ch1 = pair[1]
1142 ch1 = pair[1]
1143
1143
1144 ch0_max = numpy.max(data_acf[acf_pairs == ch0, :, :], axis=1)
1144 ch0_max = numpy.max(data_acf[acf_pairs == ch0, :, :], axis=1)
1145 ch1_max = numpy.max(data_acf[acf_pairs == ch1, :, :], axis=1)
1145 ch1_max = numpy.max(data_acf[acf_pairs == ch1, :, :], axis=1)
1146 normFactor[p, :] = numpy.sqrt(ch0_max * ch1_max)
1146 normFactor[p, :] = numpy.sqrt(ch0_max * ch1_max)
1147
1147
1148 return normFactor
1148 return normFactor
1149
1149
1150 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
1150 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
1151 normFactor = property(getNormFactor, "I'm the 'normFactor property'")
1151 normFactor = property(getNormFactor, "I'm the 'normFactor property'")
1152
1152
1153
1153
1154 class Parameters(Spectra):
1154 class Parameters(Spectra):
1155
1155
1156 experimentInfo = None # Information about the experiment
1156 experimentInfo = None # Information about the experiment
1157
1157
1158 # Information from previous data
1158 # Information from previous data
1159
1159
1160 inputUnit = None # Type of data to be processed
1160 inputUnit = None # Type of data to be processed
1161
1161
1162 operation = None # Type of operation to parametrize
1162 operation = None # Type of operation to parametrize
1163
1163
1164 # normFactor = None #Normalization Factor
1164 # normFactor = None #Normalization Factor
1165
1165
1166 groupList = None # List of Pairs, Groups, etc
1166 groupList = None # List of Pairs, Groups, etc
1167
1167
1168 # Parameters
1168 # Parameters
1169
1169
1170 data_param = None # Parameters obtained
1170 data_param = None # Parameters obtained
1171
1171
1172 data_pre = None # Data Pre Parametrization
1172 data_pre = None # Data Pre Parametrization
1173
1173
1174 data_SNR = None # Signal to Noise Ratio
1174 data_SNR = None # Signal to Noise Ratio
1175
1175
1176 # heightRange = None #Heights
1176 # heightRange = None #Heights
1177
1177
1178 abscissaList = None # Abscissa, can be velocities, lags or time
1178 abscissaList = None # Abscissa, can be velocities, lags or time
1179
1179
1180 # noise = None #Noise Potency
1180 # noise = None #Noise Potency
1181
1181
1182 utctimeInit = None # Initial UTC time
1182 utctimeInit = None # Initial UTC time
1183
1183
1184 paramInterval = None # Time interval to calculate Parameters in seconds
1184 paramInterval = None # Time interval to calculate Parameters in seconds
1185
1185
1186 useLocalTime = True
1186 useLocalTime = True
1187
1187
1188 # Fitting
1188 # Fitting
1189
1189
1190 data_error = None # Error of the estimation
1190 data_error = None # Error of the estimation
1191
1191
1192 constants = None
1192 constants = None
1193
1193
1194 library = None
1194 library = None
1195
1195
1196 # Output signal
1196 # Output signal
1197
1197
1198 outputInterval = None # Time interval to calculate output signal in seconds
1198 outputInterval = None # Time interval to calculate output signal in seconds
1199
1199
1200 data_output = None # Out signal
1200 data_output = None # Out signal
1201
1201
1202 nAvg = None
1202 nAvg = None
1203
1203
1204 noise_estimation = None
1204 noise_estimation = None
1205
1205
1206 GauSPC = None # Fit gaussian SPC
1206 GauSPC = None # Fit gaussian SPC
1207
1207
1208 def __init__(self):
1208 def __init__(self):
1209 '''
1209 '''
1210 Constructor
1210 Constructor
1211 '''
1211 '''
1212 self.radarControllerHeaderObj = RadarControllerHeader()
1212 self.radarControllerHeaderObj = RadarControllerHeader()
1213
1213
1214 self.systemHeaderObj = SystemHeader()
1214 self.systemHeaderObj = SystemHeader()
1215
1215
1216 self.type = "Parameters"
1216 self.type = "Parameters"
1217
1217
1218 def getTimeRange1(self, interval):
1218 def getTimeRange1(self, interval):
1219
1219
1220 datatime = []
1220 datatime = []
1221
1221
1222 if self.useLocalTime:
1222 if self.useLocalTime:
1223 time1 = self.utctimeInit - self.timeZone * 60
1223 time1 = self.utctimeInit - self.timeZone * 60
1224 else:
1224 else:
1225 time1 = self.utctimeInit
1225 time1 = self.utctimeInit
1226
1226
1227 datatime.append(time1)
1227 datatime.append(time1)
1228 datatime.append(time1 + interval)
1228 datatime.append(time1 + interval)
1229 datatime = numpy.array(datatime)
1229 datatime = numpy.array(datatime)
1230
1230
1231 return datatime
1231 return datatime
1232
1232
1233 def getTimeInterval(self):
1233 def getTimeInterval(self):
1234
1234
1235 if hasattr(self, 'timeInterval1'):
1235 if hasattr(self, 'timeInterval1'):
1236 return self.timeInterval1
1236 return self.timeInterval1
1237 else:
1237 else:
1238 return self.paramInterval
1238 return self.paramInterval
1239
1239
1240 def setValue(self, value):
1240 def setValue(self, value):
1241
1241
1242 print "This property should not be initialized"
1242 print("This property should not be initialized")
1243
1243
1244 return
1244 return
1245
1245
1246 def getNoise(self):
1246 def getNoise(self):
1247
1247
1248 return self.spc_noise
1248 return self.spc_noise
1249
1249
1250 timeInterval = property(getTimeInterval)
1250 timeInterval = property(getTimeInterval)
1251 noise = property(getNoise, setValue, "I'm the 'Noise' property.")
1251 noise = property(getNoise, setValue, "I'm the 'Noise' property.") No newline at end of file
@@ -1,905 +1,907
1 '''
1 '''
2
2
3 $Author: murco $
3 $Author: murco $
4 $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $
4 $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $
5 '''
5 '''
6 import sys
6 import sys
7 import numpy
7 import numpy
8 import copy
8 import copy
9 import datetime
9 import datetime
10 import inspect
10 import inspect
11 from schainpy.utils import log
11
12
12 SPEED_OF_LIGHT = 299792458
13 SPEED_OF_LIGHT = 299792458
13 SPEED_OF_LIGHT = 3e8
14 SPEED_OF_LIGHT = 3e8
14
15
15 BASIC_STRUCTURE = numpy.dtype([
16 BASIC_STRUCTURE = numpy.dtype([
16 ('nSize', '<u4'),
17 ('nSize', '<u4'),
17 ('nVersion', '<u2'),
18 ('nVersion', '<u2'),
18 ('nDataBlockId', '<u4'),
19 ('nDataBlockId', '<u4'),
19 ('nUtime', '<u4'),
20 ('nUtime', '<u4'),
20 ('nMilsec', '<u2'),
21 ('nMilsec', '<u2'),
21 ('nTimezone', '<i2'),
22 ('nTimezone', '<i2'),
22 ('nDstflag', '<i2'),
23 ('nDstflag', '<i2'),
23 ('nErrorCount', '<u4')
24 ('nErrorCount', '<u4')
24 ])
25 ])
25
26
26 SYSTEM_STRUCTURE = numpy.dtype([
27 SYSTEM_STRUCTURE = numpy.dtype([
27 ('nSize', '<u4'),
28 ('nSize', '<u4'),
28 ('nNumSamples', '<u4'),
29 ('nNumSamples', '<u4'),
29 ('nNumProfiles', '<u4'),
30 ('nNumProfiles', '<u4'),
30 ('nNumChannels', '<u4'),
31 ('nNumChannels', '<u4'),
31 ('nADCResolution', '<u4'),
32 ('nADCResolution', '<u4'),
32 ('nPCDIOBusWidth', '<u4'),
33 ('nPCDIOBusWidth', '<u4'),
33 ])
34 ])
34
35
35 RADAR_STRUCTURE = numpy.dtype([
36 RADAR_STRUCTURE = numpy.dtype([
36 ('nSize', '<u4'),
37 ('nSize', '<u4'),
37 ('nExpType', '<u4'),
38 ('nExpType', '<u4'),
38 ('nNTx', '<u4'),
39 ('nNTx', '<u4'),
39 ('fIpp', '<f4'),
40 ('fIpp', '<f4'),
40 ('fTxA', '<f4'),
41 ('fTxA', '<f4'),
41 ('fTxB', '<f4'),
42 ('fTxB', '<f4'),
42 ('nNumWindows', '<u4'),
43 ('nNumWindows', '<u4'),
43 ('nNumTaus', '<u4'),
44 ('nNumTaus', '<u4'),
44 ('nCodeType', '<u4'),
45 ('nCodeType', '<u4'),
45 ('nLine6Function', '<u4'),
46 ('nLine6Function', '<u4'),
46 ('nLine5Function', '<u4'),
47 ('nLine5Function', '<u4'),
47 ('fClock', '<f4'),
48 ('fClock', '<f4'),
48 ('nPrePulseBefore', '<u4'),
49 ('nPrePulseBefore', '<u4'),
49 ('nPrePulseAfter', '<u4'),
50 ('nPrePulseAfter', '<u4'),
50 ('sRangeIPP', '<a20'),
51 ('sRangeIPP', '<a20'),
51 ('sRangeTxA', '<a20'),
52 ('sRangeTxA', '<a20'),
52 ('sRangeTxB', '<a20'),
53 ('sRangeTxB', '<a20'),
53 ])
54 ])
54
55
55 SAMPLING_STRUCTURE = numpy.dtype(
56 SAMPLING_STRUCTURE = numpy.dtype(
56 [('h0', '<f4'), ('dh', '<f4'), ('nsa', '<u4')])
57 [('h0', '<f4'), ('dh', '<f4'), ('nsa', '<u4')])
57
58
58
59
59 PROCESSING_STRUCTURE = numpy.dtype([
60 PROCESSING_STRUCTURE = numpy.dtype([
60 ('nSize', '<u4'),
61 ('nSize', '<u4'),
61 ('nDataType', '<u4'),
62 ('nDataType', '<u4'),
62 ('nSizeOfDataBlock', '<u4'),
63 ('nSizeOfDataBlock', '<u4'),
63 ('nProfilesperBlock', '<u4'),
64 ('nProfilesperBlock', '<u4'),
64 ('nDataBlocksperFile', '<u4'),
65 ('nDataBlocksperFile', '<u4'),
65 ('nNumWindows', '<u4'),
66 ('nNumWindows', '<u4'),
66 ('nProcessFlags', '<u4'),
67 ('nProcessFlags', '<u4'),
67 ('nCoherentIntegrations', '<u4'),
68 ('nCoherentIntegrations', '<u4'),
68 ('nIncoherentIntegrations', '<u4'),
69 ('nIncoherentIntegrations', '<u4'),
69 ('nTotalSpectra', '<u4')
70 ('nTotalSpectra', '<u4')
70 ])
71 ])
71
72
72
73
73 class Header(object):
74 class Header(object):
74
75
75 def __init__(self):
76 def __init__(self):
76 raise NotImplementedError
77 raise NotImplementedError
77
78
78 def copy(self):
79 def copy(self):
79 return copy.deepcopy(self)
80 return copy.deepcopy(self)
80
81
81 def read(self):
82 def read(self):
82
83
83 raise NotImplementedError
84 raise NotImplementedError
84
85
85 def write(self):
86 def write(self):
86
87
87 raise NotImplementedError
88 raise NotImplementedError
88
89
89 def getAllowedArgs(self):
90 def getAllowedArgs(self):
90 args = inspect.getargspec(self.__init__).args
91 args = inspect.getargspec(self.__init__).args
91 try:
92 try:
92 args.remove('self')
93 args.remove('self')
93 except:
94 except:
94 pass
95 pass
95 return args
96 return args
96
97
97 def getAsDict(self):
98 def getAsDict(self):
98 args = self.getAllowedArgs()
99 args = self.getAllowedArgs()
99 asDict = {}
100 asDict = {}
100 for x in args:
101 for x in args:
101 asDict[x] = self[x]
102 asDict[x] = self[x]
102 return asDict
103 return asDict
103
104
104 def __getitem__(self, name):
105 def __getitem__(self, name):
105 return getattr(self, name)
106 return getattr(self, name)
106
107
107 def printInfo(self):
108 def printInfo(self):
108
109
109 message = "#" * 50 + "\n"
110 message = "#" * 50 + "\n"
110 message += self.__class__.__name__.upper() + "\n"
111 message += self.__class__.__name__.upper() + "\n"
111 message += "#" * 50 + "\n"
112 message += "#" * 50 + "\n"
112
113
113 keyList = self.__dict__.keys()
114 keyList = list(self.__dict__.keys())
114 keyList.sort()
115 keyList.sort()
115
116
116 for key in keyList:
117 for key in keyList:
117 message += "%s = %s" % (key, self.__dict__[key]) + "\n"
118 message += "%s = %s" % (key, self.__dict__[key]) + "\n"
118
119
119 if "size" not in keyList:
120 if "size" not in keyList:
120 attr = getattr(self, "size")
121 attr = getattr(self, "size")
121
122
122 if attr:
123 if attr:
123 message += "%s = %s" % ("size", attr) + "\n"
124 message += "%s = %s" % ("size", attr) + "\n"
124
125
125 print message
126 print(message)
126
127
127
128
128 class BasicHeader(Header):
129 class BasicHeader(Header):
129
130
130 size = None
131 size = None
131 version = None
132 version = None
132 dataBlock = None
133 dataBlock = None
133 utc = None
134 utc = None
134 ltc = None
135 ltc = None
135 miliSecond = None
136 miliSecond = None
136 timeZone = None
137 timeZone = None
137 dstFlag = None
138 dstFlag = None
138 errorCount = None
139 errorCount = None
139 datatime = None
140 datatime = None
140 structure = BASIC_STRUCTURE
141 structure = BASIC_STRUCTURE
141 __LOCALTIME = None
142 __LOCALTIME = None
142
143
143 def __init__(self, useLocalTime=True):
144 def __init__(self, useLocalTime=True):
144
145
145 self.size = 24
146 self.size = 24
146 self.version = 0
147 self.version = 0
147 self.dataBlock = 0
148 self.dataBlock = 0
148 self.utc = 0
149 self.utc = 0
149 self.miliSecond = 0
150 self.miliSecond = 0
150 self.timeZone = 0
151 self.timeZone = 0
151 self.dstFlag = 0
152 self.dstFlag = 0
152 self.errorCount = 0
153 self.errorCount = 0
153
154
154 self.useLocalTime = useLocalTime
155 self.useLocalTime = useLocalTime
155
156
156 def read(self, fp):
157 def read(self, fp):
157
158
158 self.length = 0
159 self.length = 0
159 try:
160 try:
160 if hasattr(fp, 'read'):
161 if hasattr(fp, 'read'):
161 header = numpy.fromfile(fp, BASIC_STRUCTURE, 1)
162 header = numpy.fromfile(fp, BASIC_STRUCTURE, 1)
162 else:
163 else:
163 header = numpy.fromstring(fp, BASIC_STRUCTURE, 1)
164 header = numpy.fromstring(fp, BASIC_STRUCTURE, 1)
164 except Exception, e:
165 except Exception as e:
165 print "BasicHeader: "
166 print("BasicHeader: ")
166 print e
167 print(e)
167 return 0
168 return 0
168
169
169 self.size = int(header['nSize'][0])
170 self.size = int(header['nSize'][0])
170 self.version = int(header['nVersion'][0])
171 self.version = int(header['nVersion'][0])
171 self.dataBlock = int(header['nDataBlockId'][0])
172 self.dataBlock = int(header['nDataBlockId'][0])
172 self.utc = int(header['nUtime'][0])
173 self.utc = int(header['nUtime'][0])
173 self.miliSecond = int(header['nMilsec'][0])
174 self.miliSecond = int(header['nMilsec'][0])
174 self.timeZone = int(header['nTimezone'][0])
175 self.timeZone = int(header['nTimezone'][0])
175 self.dstFlag = int(header['nDstflag'][0])
176 self.dstFlag = int(header['nDstflag'][0])
176 self.errorCount = int(header['nErrorCount'][0])
177 self.errorCount = int(header['nErrorCount'][0])
177
178
178 if self.size < 24:
179 if self.size < 24:
179 return 0
180 return 0
180
181
181 self.length = header.nbytes
182 self.length = header.nbytes
182 return 1
183 return 1
183
184
184 def write(self, fp):
185 def write(self, fp):
185
186
186 headerTuple = (self.size, self.version, self.dataBlock, self.utc,
187 headerTuple = (self.size, self.version, self.dataBlock, self.utc,
187 self.miliSecond, self.timeZone, self.dstFlag, self.errorCount)
188 self.miliSecond, self.timeZone, self.dstFlag, self.errorCount)
188 header = numpy.array(headerTuple, BASIC_STRUCTURE)
189 header = numpy.array(headerTuple, BASIC_STRUCTURE)
189 header.tofile(fp)
190 header.tofile(fp)
190
191
191 return 1
192 return 1
192
193
193 def get_ltc(self):
194 def get_ltc(self):
194
195
195 return self.utc - self.timeZone * 60
196 return self.utc - self.timeZone * 60
196
197
197 def set_ltc(self, value):
198 def set_ltc(self, value):
198
199
199 self.utc = value + self.timeZone * 60
200 self.utc = value + self.timeZone * 60
200
201
201 def get_datatime(self):
202 def get_datatime(self):
202
203
203 return datetime.datetime.utcfromtimestamp(self.ltc)
204 return datetime.datetime.utcfromtimestamp(self.ltc)
204
205
205 ltc = property(get_ltc, set_ltc)
206 ltc = property(get_ltc, set_ltc)
206 datatime = property(get_datatime)
207 datatime = property(get_datatime)
207
208
208
209
209 class SystemHeader(Header):
210 class SystemHeader(Header):
210
211
211 size = None
212 size = None
212 nSamples = None
213 nSamples = None
213 nProfiles = None
214 nProfiles = None
214 nChannels = None
215 nChannels = None
215 adcResolution = None
216 adcResolution = None
216 pciDioBusWidth = None
217 pciDioBusWidth = None
217 structure = SYSTEM_STRUCTURE
218 structure = SYSTEM_STRUCTURE
218
219
219 def __init__(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWidth=0):
220 def __init__(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWidth=0):
220
221
221 self.size = 24
222 self.size = 24
222 self.nSamples = nSamples
223 self.nSamples = nSamples
223 self.nProfiles = nProfiles
224 self.nProfiles = nProfiles
224 self.nChannels = nChannels
225 self.nChannels = nChannels
225 self.adcResolution = adcResolution
226 self.adcResolution = adcResolution
226 self.pciDioBusWidth = pciDioBusWidth
227 self.pciDioBusWidth = pciDioBusWidth
227
228
228 def read(self, fp):
229 def read(self, fp):
229 self.length = 0
230 self.length = 0
230 try:
231 try:
231 startFp = fp.tell()
232 startFp = fp.tell()
232 except Exception, e:
233 except Exception as e:
233 startFp = None
234 startFp = None
234 pass
235 pass
235
236
236 try:
237 try:
237 if hasattr(fp, 'read'):
238 if hasattr(fp, 'read'):
238 header = numpy.fromfile(fp, SYSTEM_STRUCTURE, 1)
239 header = numpy.fromfile(fp, SYSTEM_STRUCTURE, 1)
239 else:
240 else:
240 header = numpy.fromstring(fp, SYSTEM_STRUCTURE, 1)
241 header = numpy.fromstring(fp, SYSTEM_STRUCTURE, 1)
241 except Exception, e:
242 except Exception as e:
242 print "System Header: " + str(e)
243 print("System Header: " + str(e))
243 return 0
244 return 0
244
245
245 self.size = header['nSize'][0]
246 self.size = header['nSize'][0]
246 self.nSamples = header['nNumSamples'][0]
247 self.nSamples = header['nNumSamples'][0]
247 self.nProfiles = header['nNumProfiles'][0]
248 self.nProfiles = header['nNumProfiles'][0]
248 self.nChannels = header['nNumChannels'][0]
249 self.nChannels = header['nNumChannels'][0]
249 self.adcResolution = header['nADCResolution'][0]
250 self.adcResolution = header['nADCResolution'][0]
250 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
251 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
251
252
252 if startFp is not None:
253 if startFp is not None:
253 endFp = self.size + startFp
254 endFp = self.size + startFp
254
255
255 if fp.tell() > endFp:
256 if fp.tell() > endFp:
256 sys.stderr.write(
257 sys.stderr.write(
257 "Warning %s: Size value read from System Header is lower than it has to be\n" % fp.name)
258 "Warning %s: Size value read from System Header is lower than it has to be\n" % fp.name)
258 return 0
259 return 0
259
260
260 if fp.tell() < endFp:
261 if fp.tell() < endFp:
261 sys.stderr.write(
262 sys.stderr.write(
262 "Warning %s: Size value read from System Header size is greater than it has to be\n" % fp.name)
263 "Warning %s: Size value read from System Header size is greater than it has to be\n" % fp.name)
263 return 0
264 return 0
264
265
265 self.length = header.nbytes
266 self.length = header.nbytes
266 return 1
267 return 1
267
268
268 def write(self, fp):
269 def write(self, fp):
269
270
270 headerTuple = (self.size, self.nSamples, self.nProfiles,
271 headerTuple = (self.size, self.nSamples, self.nProfiles,
271 self.nChannels, self.adcResolution, self.pciDioBusWidth)
272 self.nChannels, self.adcResolution, self.pciDioBusWidth)
272 header = numpy.array(headerTuple, SYSTEM_STRUCTURE)
273 header = numpy.array(headerTuple, SYSTEM_STRUCTURE)
273 header.tofile(fp)
274 header.tofile(fp)
274
275
275 return 1
276 return 1
276
277
277
278
278 class RadarControllerHeader(Header):
279 class RadarControllerHeader(Header):
279
280
280 expType = None
281 expType = None
281 nTx = None
282 nTx = None
282 ipp = None
283 ipp = None
283 txA = None
284 txA = None
284 txB = None
285 txB = None
285 nWindows = None
286 nWindows = None
286 numTaus = None
287 numTaus = None
287 codeType = None
288 codeType = None
288 line6Function = None
289 line6Function = None
289 line5Function = None
290 line5Function = None
290 fClock = None
291 fClock = None
291 prePulseBefore = None
292 prePulseBefore = None
292 prePulseAfter = None
293 prePulseAfter = None
293 rangeIpp = None
294 rangeIpp = None
294 rangeTxA = None
295 rangeTxA = None
295 rangeTxB = None
296 rangeTxB = None
296 structure = RADAR_STRUCTURE
297 structure = RADAR_STRUCTURE
297 __size = None
298 __size = None
298
299
299 def __init__(self, expType=2, nTx=1,
300 def __init__(self, expType=2, nTx=1,
300 ipp=None, txA=0, txB=0,
301 ipp=None, txA=0, txB=0,
301 nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None,
302 nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None,
302 numTaus=0, line6Function=0, line5Function=0, fClock=None,
303 numTaus=0, line6Function=0, line5Function=0, fClock=None,
303 prePulseBefore=0, prePulseAfter=0,
304 prePulseBefore=0, prePulseAfter=0,
304 codeType=0, nCode=0, nBaud=0, code=None,
305 codeType=0, nCode=0, nBaud=0, code=None,
305 flip1=0, flip2=0):
306 flip1=0, flip2=0):
306
307
307 # self.size = 116
308 # self.size = 116
308 self.expType = expType
309 self.expType = expType
309 self.nTx = nTx
310 self.nTx = nTx
310 self.ipp = ipp
311 self.ipp = ipp
311 self.txA = txA
312 self.txA = txA
312 self.txB = txB
313 self.txB = txB
313 self.rangeIpp = ipp
314 self.rangeIpp = ipp
314 self.rangeTxA = txA
315 self.rangeTxA = txA
315 self.rangeTxB = txB
316 self.rangeTxB = txB
316
317
317 self.nWindows = nWindows
318 self.nWindows = nWindows
318 self.numTaus = numTaus
319 self.numTaus = numTaus
319 self.codeType = codeType
320 self.codeType = codeType
320 self.line6Function = line6Function
321 self.line6Function = line6Function
321 self.line5Function = line5Function
322 self.line5Function = line5Function
322 self.fClock = fClock
323 self.fClock = fClock
323 self.prePulseBefore = prePulseBefore
324 self.prePulseBefore = prePulseBefore
324 self.prePulseAfter = prePulseAfter
325 self.prePulseAfter = prePulseAfter
325
326
326 self.nHeights = nHeights
327 self.nHeights = nHeights
327 self.firstHeight = firstHeight
328 self.firstHeight = firstHeight
328 self.deltaHeight = deltaHeight
329 self.deltaHeight = deltaHeight
329 self.samplesWin = nHeights
330 self.samplesWin = nHeights
330
331
331 self.nCode = nCode
332 self.nCode = nCode
332 self.nBaud = nBaud
333 self.nBaud = nBaud
333 self.code = code
334 self.code = code
334 self.flip1 = flip1
335 self.flip1 = flip1
335 self.flip2 = flip2
336 self.flip2 = flip2
336
337
337 self.code_size = int(numpy.ceil(self.nBaud / 32.)) * self.nCode * 4
338 self.code_size = int(numpy.ceil(self.nBaud / 32.)) * self.nCode * 4
338 # self.dynamic = numpy.array([],numpy.dtype('byte'))
339 # self.dynamic = numpy.array([],numpy.dtype('byte'))
339
340
340 if self.fClock is None and self.deltaHeight is not None:
341 if self.fClock is None and self.deltaHeight is not None:
341 self.fClock = 0.15 / (deltaHeight * 1e-6) # 0.15Km / (height * 1u)
342 self.fClock = 0.15 / (deltaHeight * 1e-6) # 0.15Km / (height * 1u)
342
343
343 def read(self, fp):
344 def read(self, fp):
344 self.length = 0
345 self.length = 0
345 try:
346 try:
346 startFp = fp.tell()
347 startFp = fp.tell()
347 except Exception, e:
348 except Exception as e:
348 startFp = None
349 startFp = None
349 pass
350 pass
350
351
351 try:
352 try:
352 if hasattr(fp, 'read'):
353 if hasattr(fp, 'read'):
353 header = numpy.fromfile(fp, RADAR_STRUCTURE, 1)
354 header = numpy.fromfile(fp, RADAR_STRUCTURE, 1)
354 else:
355 else:
355 header = numpy.fromstring(fp, RADAR_STRUCTURE, 1)
356 header = numpy.fromstring(fp, RADAR_STRUCTURE, 1)
356 self.length += header.nbytes
357 self.length += header.nbytes
357 except Exception, e:
358 except Exception as e:
358 print "RadarControllerHeader: " + str(e)
359 print("RadarControllerHeader: " + str(e))
359 return 0
360 return 0
360
361
361 size = int(header['nSize'][0])
362 size = int(header['nSize'][0])
362 self.expType = int(header['nExpType'][0])
363 self.expType = int(header['nExpType'][0])
363 self.nTx = int(header['nNTx'][0])
364 self.nTx = int(header['nNTx'][0])
364 self.ipp = float(header['fIpp'][0])
365 self.ipp = float(header['fIpp'][0])
365 self.txA = float(header['fTxA'][0])
366 self.txA = float(header['fTxA'][0])
366 self.txB = float(header['fTxB'][0])
367 self.txB = float(header['fTxB'][0])
367 self.nWindows = int(header['nNumWindows'][0])
368 self.nWindows = int(header['nNumWindows'][0])
368 self.numTaus = int(header['nNumTaus'][0])
369 self.numTaus = int(header['nNumTaus'][0])
369 self.codeType = int(header['nCodeType'][0])
370 self.codeType = int(header['nCodeType'][0])
370 self.line6Function = int(header['nLine6Function'][0])
371 self.line6Function = int(header['nLine6Function'][0])
371 self.line5Function = int(header['nLine5Function'][0])
372 self.line5Function = int(header['nLine5Function'][0])
372 self.fClock = float(header['fClock'][0])
373 self.fClock = float(header['fClock'][0])
373 self.prePulseBefore = int(header['nPrePulseBefore'][0])
374 self.prePulseBefore = int(header['nPrePulseBefore'][0])
374 self.prePulseAfter = int(header['nPrePulseAfter'][0])
375 self.prePulseAfter = int(header['nPrePulseAfter'][0])
375 self.rangeIpp = header['sRangeIPP'][0]
376 self.rangeIpp = header['sRangeIPP'][0]
376 self.rangeTxA = header['sRangeTxA'][0]
377 self.rangeTxA = header['sRangeTxA'][0]
377 self.rangeTxB = header['sRangeTxB'][0]
378 self.rangeTxB = header['sRangeTxB'][0]
378
379
379 try:
380 try:
380 if hasattr(fp, 'read'):
381 if hasattr(fp, 'read'):
381 samplingWindow = numpy.fromfile(
382 samplingWindow = numpy.fromfile(
382 fp, SAMPLING_STRUCTURE, self.nWindows)
383 fp, SAMPLING_STRUCTURE, self.nWindows)
383 else:
384 else:
384 samplingWindow = numpy.fromstring(
385 samplingWindow = numpy.fromstring(
385 fp[self.length:], SAMPLING_STRUCTURE, self.nWindows)
386 fp[self.length:], SAMPLING_STRUCTURE, self.nWindows)
386 self.length += samplingWindow.nbytes
387 self.length += samplingWindow.nbytes
387 except Exception, e:
388 except Exception as e:
388 print "RadarControllerHeader: " + str(e)
389 print("RadarControllerHeader: " + str(e))
389 return 0
390 return 0
390 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
391 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
391 self.firstHeight = samplingWindow['h0']
392 self.firstHeight = samplingWindow['h0']
392 self.deltaHeight = samplingWindow['dh']
393 self.deltaHeight = samplingWindow['dh']
393 self.samplesWin = samplingWindow['nsa']
394 self.samplesWin = samplingWindow['nsa']
394
395
395 try:
396 try:
396 if hasattr(fp, 'read'):
397 if hasattr(fp, 'read'):
397 self.Taus = numpy.fromfile(fp, '<f4', self.numTaus)
398 self.Taus = numpy.fromfile(fp, '<f4', self.numTaus)
398 else:
399 else:
399 self.Taus = numpy.fromstring(
400 self.Taus = numpy.fromstring(
400 fp[self.length:], '<f4', self.numTaus)
401 fp[self.length:], '<f4', self.numTaus)
401 self.length += self.Taus.nbytes
402 self.length += self.Taus.nbytes
402 except Exception, e:
403 except Exception as e:
403 print "RadarControllerHeader: " + str(e)
404 print("RadarControllerHeader: " + str(e))
404 return 0
405 return 0
405
406
406 self.code_size = 0
407 self.code_size = 0
407 if self.codeType != 0:
408 if self.codeType != 0:
408
409
409 try:
410 try:
410 if hasattr(fp, 'read'):
411 if hasattr(fp, 'read'):
411 self.nCode = numpy.fromfile(fp, '<u4', 1)[0]
412 self.nCode = numpy.fromfile(fp, '<u4', 1)[0]
412 self.length += self.nCode.nbytes
413 self.length += self.nCode.nbytes
413 self.nBaud = numpy.fromfile(fp, '<u4', 1)[0]
414 self.nBaud = numpy.fromfile(fp, '<u4', 1)[0]
414 self.length += self.nBaud.nbytes
415 self.length += self.nBaud.nbytes
415 else:
416 else:
416 self.nCode = numpy.fromstring(
417 self.nCode = numpy.fromstring(
417 fp[self.length:], '<u4', 1)[0]
418 fp[self.length:], '<u4', 1)[0]
418 self.length += self.nCode.nbytes
419 self.length += self.nCode.nbytes
419 self.nBaud = numpy.fromstring(
420 self.nBaud = numpy.fromstring(
420 fp[self.length:], '<u4', 1)[0]
421 fp[self.length:], '<u4', 1)[0]
421 self.length += self.nBaud.nbytes
422 self.length += self.nBaud.nbytes
422 except Exception, e:
423 except Exception as e:
423 print "RadarControllerHeader: " + str(e)
424 print("RadarControllerHeader: " + str(e))
424 return 0
425 return 0
425 code = numpy.empty([self.nCode, self.nBaud], dtype='i1')
426 code = numpy.empty([self.nCode, self.nBaud], dtype='i1')
426
427
427 for ic in range(self.nCode):
428 for ic in range(self.nCode):
428 try:
429 try:
429 if hasattr(fp, 'read'):
430 if hasattr(fp, 'read'):
430 temp = numpy.fromfile(fp, 'u4', int(
431 temp = numpy.fromfile(fp, 'u4', int(
431 numpy.ceil(self.nBaud / 32.)))
432 numpy.ceil(self.nBaud / 32.)))
432 else:
433 else:
433 temp = numpy.fromstring(
434 temp = numpy.fromstring(
434 fp, 'u4', int(numpy.ceil(self.nBaud / 32.)))
435 fp, 'u4', int(numpy.ceil(self.nBaud / 32.)))
435 self.length += temp.nbytes
436 self.length += temp.nbytes
436 except Exception, e:
437 except Exception as e:
437 print "RadarControllerHeader: " + str(e)
438 print("RadarControllerHeader: " + str(e))
438 return 0
439 return 0
439
440
440 for ib in range(self.nBaud - 1, -1, -1):
441 for ib in range(self.nBaud - 1, -1, -1):
441 code[ic, ib] = temp[ib / 32] % 2
442 log.error(ib / 32)
442 temp[ib / 32] = temp[ib / 32] / 2
443 code[ic, ib] = temp[int(ib / 32)] % 2
444 temp[int(ib / 32)] = temp[int(ib / 32)] / 2
443
445
444 self.code = 2.0 * code - 1.0
446 self.code = 2.0 * code - 1.0
445 self.code_size = int(numpy.ceil(self.nBaud / 32.)) * self.nCode * 4
447 self.code_size = int(numpy.ceil(self.nBaud / 32.)) * self.nCode * 4
446
448
447 # if self.line5Function == RCfunction.FLIP:
449 # if self.line5Function == RCfunction.FLIP:
448 # self.flip1 = numpy.fromfile(fp,'<u4',1)
450 # self.flip1 = numpy.fromfile(fp,'<u4',1)
449 #
451 #
450 # if self.line6Function == RCfunction.FLIP:
452 # if self.line6Function == RCfunction.FLIP:
451 # self.flip2 = numpy.fromfile(fp,'<u4',1)
453 # self.flip2 = numpy.fromfile(fp,'<u4',1)
452 if startFp is not None:
454 if startFp is not None:
453 endFp = size + startFp
455 endFp = size + startFp
454
456
455 if fp.tell() != endFp:
457 if fp.tell() != endFp:
456 # fp.seek(endFp)
458 # fp.seek(endFp)
457 print "%s: Radar Controller Header size is not consistent: from data [%d] != from header field [%d]" % (fp.name, fp.tell() - startFp, size)
459 print("%s: Radar Controller Header size is not consistent: from data [%d] != from header field [%d]" % (fp.name, fp.tell() - startFp, size))
458 # return 0
460 # return 0
459
461
460 if fp.tell() > endFp:
462 if fp.tell() > endFp:
461 sys.stderr.write(
463 sys.stderr.write(
462 "Warning %s: Size value read from Radar Controller header is lower than it has to be\n" % fp.name)
464 "Warning %s: Size value read from Radar Controller header is lower than it has to be\n" % fp.name)
463 # return 0
465 # return 0
464
466
465 if fp.tell() < endFp:
467 if fp.tell() < endFp:
466 sys.stderr.write(
468 sys.stderr.write(
467 "Warning %s: Size value read from Radar Controller header is greater than it has to be\n" % fp.name)
469 "Warning %s: Size value read from Radar Controller header is greater than it has to be\n" % fp.name)
468
470
469 return 1
471 return 1
470
472
471 def write(self, fp):
473 def write(self, fp):
472
474
473 headerTuple = (self.size,
475 headerTuple = (self.size,
474 self.expType,
476 self.expType,
475 self.nTx,
477 self.nTx,
476 self.ipp,
478 self.ipp,
477 self.txA,
479 self.txA,
478 self.txB,
480 self.txB,
479 self.nWindows,
481 self.nWindows,
480 self.numTaus,
482 self.numTaus,
481 self.codeType,
483 self.codeType,
482 self.line6Function,
484 self.line6Function,
483 self.line5Function,
485 self.line5Function,
484 self.fClock,
486 self.fClock,
485 self.prePulseBefore,
487 self.prePulseBefore,
486 self.prePulseAfter,
488 self.prePulseAfter,
487 self.rangeIpp,
489 self.rangeIpp,
488 self.rangeTxA,
490 self.rangeTxA,
489 self.rangeTxB)
491 self.rangeTxB)
490
492
491 header = numpy.array(headerTuple, RADAR_STRUCTURE)
493 header = numpy.array(headerTuple, RADAR_STRUCTURE)
492 header.tofile(fp)
494 header.tofile(fp)
493
495
494 sampleWindowTuple = (
496 sampleWindowTuple = (
495 self.firstHeight, self.deltaHeight, self.samplesWin)
497 self.firstHeight, self.deltaHeight, self.samplesWin)
496 samplingWindow = numpy.array(sampleWindowTuple, SAMPLING_STRUCTURE)
498 samplingWindow = numpy.array(sampleWindowTuple, SAMPLING_STRUCTURE)
497 samplingWindow.tofile(fp)
499 samplingWindow.tofile(fp)
498
500
499 if self.numTaus > 0:
501 if self.numTaus > 0:
500 self.Taus.tofile(fp)
502 self.Taus.tofile(fp)
501
503
502 if self.codeType != 0:
504 if self.codeType != 0:
503 nCode = numpy.array(self.nCode, '<u4')
505 nCode = numpy.array(self.nCode, '<u4')
504 nCode.tofile(fp)
506 nCode.tofile(fp)
505 nBaud = numpy.array(self.nBaud, '<u4')
507 nBaud = numpy.array(self.nBaud, '<u4')
506 nBaud.tofile(fp)
508 nBaud.tofile(fp)
507 code1 = (self.code + 1.0) / 2.
509 code1 = (self.code + 1.0) / 2.
508
510
509 for ic in range(self.nCode):
511 for ic in range(self.nCode):
510 tempx = numpy.zeros(int(numpy.ceil(self.nBaud / 32.)))
512 tempx = numpy.zeros(int(numpy.ceil(self.nBaud / 32.)))
511 start = 0
513 start = 0
512 end = 32
514 end = 32
513 for i in range(len(tempx)):
515 for i in range(len(tempx)):
514 code_selected = code1[ic, start:end]
516 code_selected = code1[ic, start:end]
515 for j in range(len(code_selected) - 1, -1, -1):
517 for j in range(len(code_selected) - 1, -1, -1):
516 if code_selected[j] == 1:
518 if code_selected[j] == 1:
517 tempx[i] = tempx[i] + \
519 tempx[i] = tempx[i] + \
518 2**(len(code_selected) - 1 - j)
520 2**(len(code_selected) - 1 - j)
519 start = start + 32
521 start = start + 32
520 end = end + 32
522 end = end + 32
521
523
522 tempx = tempx.astype('u4')
524 tempx = tempx.astype('u4')
523 tempx.tofile(fp)
525 tempx.tofile(fp)
524
526
525 # if self.line5Function == RCfunction.FLIP:
527 # if self.line5Function == RCfunction.FLIP:
526 # self.flip1.tofile(fp)
528 # self.flip1.tofile(fp)
527 #
529 #
528 # if self.line6Function == RCfunction.FLIP:
530 # if self.line6Function == RCfunction.FLIP:
529 # self.flip2.tofile(fp)
531 # self.flip2.tofile(fp)
530
532
531 return 1
533 return 1
532
534
533 def get_ippSeconds(self):
535 def get_ippSeconds(self):
534 '''
536 '''
535 '''
537 '''
536 ippSeconds = 2.0 * 1000 * self.ipp / SPEED_OF_LIGHT
538 ippSeconds = 2.0 * 1000 * self.ipp / SPEED_OF_LIGHT
537
539
538 return ippSeconds
540 return ippSeconds
539
541
540 def set_ippSeconds(self, ippSeconds):
542 def set_ippSeconds(self, ippSeconds):
541 '''
543 '''
542 '''
544 '''
543
545
544 self.ipp = ippSeconds * SPEED_OF_LIGHT / (2.0 * 1000)
546 self.ipp = ippSeconds * SPEED_OF_LIGHT / (2.0 * 1000)
545
547
546 return
548 return
547
549
548 def get_size(self):
550 def get_size(self):
549
551
550 self.__size = 116 + 12 * self.nWindows + 4 * self.numTaus
552 self.__size = 116 + 12 * self.nWindows + 4 * self.numTaus
551
553
552 if self.codeType != 0:
554 if self.codeType != 0:
553 self.__size += 4 + 4 + 4 * self.nCode * \
555 self.__size += 4 + 4 + 4 * self.nCode * \
554 numpy.ceil(self.nBaud / 32.)
556 numpy.ceil(self.nBaud / 32.)
555
557
556 return self.__size
558 return self.__size
557
559
558 def set_size(self, value):
560 def set_size(self, value):
559
561
560 raise IOError, "size is a property and it cannot be set, just read"
562 raise IOError("size is a property and it cannot be set, just read")
561
563
562 return
564 return
563
565
564 ippSeconds = property(get_ippSeconds, set_ippSeconds)
566 ippSeconds = property(get_ippSeconds, set_ippSeconds)
565 size = property(get_size, set_size)
567 size = property(get_size, set_size)
566
568
567
569
568 class ProcessingHeader(Header):
570 class ProcessingHeader(Header):
569
571
570 # size = None
572 # size = None
571 dtype = None
573 dtype = None
572 blockSize = None
574 blockSize = None
573 profilesPerBlock = None
575 profilesPerBlock = None
574 dataBlocksPerFile = None
576 dataBlocksPerFile = None
575 nWindows = None
577 nWindows = None
576 processFlags = None
578 processFlags = None
577 nCohInt = None
579 nCohInt = None
578 nIncohInt = None
580 nIncohInt = None
579 totalSpectra = None
581 totalSpectra = None
580 structure = PROCESSING_STRUCTURE
582 structure = PROCESSING_STRUCTURE
581 flag_dc = None
583 flag_dc = None
582 flag_cspc = None
584 flag_cspc = None
583
585
584 def __init__(self, dtype=0, blockSize=0, profilesPerBlock=0, dataBlocksPerFile=0, nWindows=0, processFlags=0, nCohInt=0,
586 def __init__(self, dtype=0, blockSize=0, profilesPerBlock=0, dataBlocksPerFile=0, nWindows=0, processFlags=0, nCohInt=0,
585 nIncohInt=0, totalSpectra=0, nHeights=0, firstHeight=0, deltaHeight=0, samplesWin=0, spectraComb=0, nCode=0,
587 nIncohInt=0, totalSpectra=0, nHeights=0, firstHeight=0, deltaHeight=0, samplesWin=0, spectraComb=0, nCode=0,
586 code=0, nBaud=None, shif_fft=False, flag_dc=False, flag_cspc=False, flag_decode=False, flag_deflip=False
588 code=0, nBaud=None, shif_fft=False, flag_dc=False, flag_cspc=False, flag_decode=False, flag_deflip=False
587 ):
589 ):
588
590
589 # self.size = 0
591 # self.size = 0
590 self.dtype = dtype
592 self.dtype = dtype
591 self.blockSize = blockSize
593 self.blockSize = blockSize
592 self.profilesPerBlock = 0
594 self.profilesPerBlock = 0
593 self.dataBlocksPerFile = 0
595 self.dataBlocksPerFile = 0
594 self.nWindows = 0
596 self.nWindows = 0
595 self.processFlags = 0
597 self.processFlags = 0
596 self.nCohInt = 0
598 self.nCohInt = 0
597 self.nIncohInt = 0
599 self.nIncohInt = 0
598 self.totalSpectra = 0
600 self.totalSpectra = 0
599
601
600 self.nHeights = 0
602 self.nHeights = 0
601 self.firstHeight = 0
603 self.firstHeight = 0
602 self.deltaHeight = 0
604 self.deltaHeight = 0
603 self.samplesWin = 0
605 self.samplesWin = 0
604 self.spectraComb = 0
606 self.spectraComb = 0
605 self.nCode = None
607 self.nCode = None
606 self.code = None
608 self.code = None
607 self.nBaud = None
609 self.nBaud = None
608
610
609 self.shif_fft = False
611 self.shif_fft = False
610 self.flag_dc = False
612 self.flag_dc = False
611 self.flag_cspc = False
613 self.flag_cspc = False
612 self.flag_decode = False
614 self.flag_decode = False
613 self.flag_deflip = False
615 self.flag_deflip = False
614 self.length = 0
616 self.length = 0
615
617
616 def read(self, fp):
618 def read(self, fp):
617 self.length = 0
619 self.length = 0
618 try:
620 try:
619 startFp = fp.tell()
621 startFp = fp.tell()
620 except Exception, e:
622 except Exception as e:
621 startFp = None
623 startFp = None
622 pass
624 pass
623
625
624 try:
626 try:
625 if hasattr(fp, 'read'):
627 if hasattr(fp, 'read'):
626 header = numpy.fromfile(fp, PROCESSING_STRUCTURE, 1)
628 header = numpy.fromfile(fp, PROCESSING_STRUCTURE, 1)
627 else:
629 else:
628 header = numpy.fromstring(fp, PROCESSING_STRUCTURE, 1)
630 header = numpy.fromstring(fp, PROCESSING_STRUCTURE, 1)
629 self.length += header.nbytes
631 self.length += header.nbytes
630 except Exception, e:
632 except Exception as e:
631 print "ProcessingHeader: " + str(e)
633 print("ProcessingHeader: " + str(e))
632 return 0
634 return 0
633
635
634 size = int(header['nSize'][0])
636 size = int(header['nSize'][0])
635 self.dtype = int(header['nDataType'][0])
637 self.dtype = int(header['nDataType'][0])
636 self.blockSize = int(header['nSizeOfDataBlock'][0])
638 self.blockSize = int(header['nSizeOfDataBlock'][0])
637 self.profilesPerBlock = int(header['nProfilesperBlock'][0])
639 self.profilesPerBlock = int(header['nProfilesperBlock'][0])
638 self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0])
640 self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0])
639 self.nWindows = int(header['nNumWindows'][0])
641 self.nWindows = int(header['nNumWindows'][0])
640 self.processFlags = header['nProcessFlags']
642 self.processFlags = header['nProcessFlags']
641 self.nCohInt = int(header['nCoherentIntegrations'][0])
643 self.nCohInt = int(header['nCoherentIntegrations'][0])
642 self.nIncohInt = int(header['nIncoherentIntegrations'][0])
644 self.nIncohInt = int(header['nIncoherentIntegrations'][0])
643 self.totalSpectra = int(header['nTotalSpectra'][0])
645 self.totalSpectra = int(header['nTotalSpectra'][0])
644
646
645 try:
647 try:
646 if hasattr(fp, 'read'):
648 if hasattr(fp, 'read'):
647 samplingWindow = numpy.fromfile(
649 samplingWindow = numpy.fromfile(
648 fp, SAMPLING_STRUCTURE, self.nWindows)
650 fp, SAMPLING_STRUCTURE, self.nWindows)
649 else:
651 else:
650 samplingWindow = numpy.fromstring(
652 samplingWindow = numpy.fromstring(
651 fp[self.length:], SAMPLING_STRUCTURE, self.nWindows)
653 fp[self.length:], SAMPLING_STRUCTURE, self.nWindows)
652 self.length += samplingWindow.nbytes
654 self.length += samplingWindow.nbytes
653 except Exception, e:
655 except Exception as e:
654 print "ProcessingHeader: " + str(e)
656 print("ProcessingHeader: " + str(e))
655 return 0
657 return 0
656
658
657 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
659 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
658 self.firstHeight = float(samplingWindow['h0'][0])
660 self.firstHeight = float(samplingWindow['h0'][0])
659 self.deltaHeight = float(samplingWindow['dh'][0])
661 self.deltaHeight = float(samplingWindow['dh'][0])
660 self.samplesWin = samplingWindow['nsa'][0]
662 self.samplesWin = samplingWindow['nsa'][0]
661
663
662 try:
664 try:
663 if hasattr(fp, 'read'):
665 if hasattr(fp, 'read'):
664 self.spectraComb = numpy.fromfile(
666 self.spectraComb = numpy.fromfile(
665 fp, 'u1', 2 * self.totalSpectra)
667 fp, 'u1', 2 * self.totalSpectra)
666 else:
668 else:
667 self.spectraComb = numpy.fromstring(
669 self.spectraComb = numpy.fromstring(
668 fp[self.length:], 'u1', 2 * self.totalSpectra)
670 fp[self.length:], 'u1', 2 * self.totalSpectra)
669 self.length += self.spectraComb.nbytes
671 self.length += self.spectraComb.nbytes
670 except Exception, e:
672 except Exception as e:
671 print "ProcessingHeader: " + str(e)
673 print("ProcessingHeader: " + str(e))
672 return 0
674 return 0
673
675
674 if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
676 if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
675 self.nCode = int(numpy.fromfile(fp, '<u4', 1))
677 self.nCode = int(numpy.fromfile(fp, '<u4', 1))
676 self.nBaud = int(numpy.fromfile(fp, '<u4', 1))
678 self.nBaud = int(numpy.fromfile(fp, '<u4', 1))
677 self.code = numpy.fromfile(
679 self.code = numpy.fromfile(
678 fp, '<f4', self.nCode * self.nBaud).reshape(self.nCode, self.nBaud)
680 fp, '<f4', self.nCode * self.nBaud).reshape(self.nCode, self.nBaud)
679
681
680 if ((self.processFlags & PROCFLAG.EXP_NAME_ESP) == PROCFLAG.EXP_NAME_ESP):
682 if ((self.processFlags & PROCFLAG.EXP_NAME_ESP) == PROCFLAG.EXP_NAME_ESP):
681 exp_name_len = int(numpy.fromfile(fp, '<u4', 1))
683 exp_name_len = int(numpy.fromfile(fp, '<u4', 1))
682 exp_name = numpy.fromfile(fp, 'u1', exp_name_len + 1)
684 exp_name = numpy.fromfile(fp, 'u1', exp_name_len + 1)
683
685
684 if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA):
686 if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA):
685 self.shif_fft = True
687 self.shif_fft = True
686 else:
688 else:
687 self.shif_fft = False
689 self.shif_fft = False
688
690
689 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
691 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
690 self.flag_dc = True
692 self.flag_dc = True
691 else:
693 else:
692 self.flag_dc = False
694 self.flag_dc = False
693
695
694 if ((self.processFlags & PROCFLAG.DECODE_DATA) == PROCFLAG.DECODE_DATA):
696 if ((self.processFlags & PROCFLAG.DECODE_DATA) == PROCFLAG.DECODE_DATA):
695 self.flag_decode = True
697 self.flag_decode = True
696 else:
698 else:
697 self.flag_decode = False
699 self.flag_decode = False
698
700
699 if ((self.processFlags & PROCFLAG.DEFLIP_DATA) == PROCFLAG.DEFLIP_DATA):
701 if ((self.processFlags & PROCFLAG.DEFLIP_DATA) == PROCFLAG.DEFLIP_DATA):
700 self.flag_deflip = True
702 self.flag_deflip = True
701 else:
703 else:
702 self.flag_deflip = False
704 self.flag_deflip = False
703
705
704 nChannels = 0
706 nChannels = 0
705 nPairs = 0
707 nPairs = 0
706 pairList = []
708 pairList = []
707
709
708 for i in range(0, self.totalSpectra * 2, 2):
710 for i in range(0, self.totalSpectra * 2, 2):
709 if self.spectraComb[i] == self.spectraComb[i + 1]:
711 if self.spectraComb[i] == self.spectraComb[i + 1]:
710 nChannels = nChannels + 1 # par de canales iguales
712 nChannels = nChannels + 1 # par de canales iguales
711 else:
713 else:
712 nPairs = nPairs + 1 # par de canales diferentes
714 nPairs = nPairs + 1 # par de canales diferentes
713 pairList.append((self.spectraComb[i], self.spectraComb[i + 1]))
715 pairList.append((self.spectraComb[i], self.spectraComb[i + 1]))
714
716
715 self.flag_cspc = False
717 self.flag_cspc = False
716 if nPairs > 0:
718 if nPairs > 0:
717 self.flag_cspc = True
719 self.flag_cspc = True
718
720
719 if startFp is not None:
721 if startFp is not None:
720 endFp = size + startFp
722 endFp = size + startFp
721 if fp.tell() > endFp:
723 if fp.tell() > endFp:
722 sys.stderr.write(
724 sys.stderr.write(
723 "Warning: Processing header size is lower than it has to be")
725 "Warning: Processing header size is lower than it has to be")
724 return 0
726 return 0
725
727
726 if fp.tell() < endFp:
728 if fp.tell() < endFp:
727 sys.stderr.write(
729 sys.stderr.write(
728 "Warning: Processing header size is greater than it is considered")
730 "Warning: Processing header size is greater than it is considered")
729
731
730 return 1
732 return 1
731
733
732 def write(self, fp):
734 def write(self, fp):
733 # Clear DEFINE_PROCESS_CODE
735 # Clear DEFINE_PROCESS_CODE
734 self.processFlags = self.processFlags & (~PROCFLAG.DEFINE_PROCESS_CODE)
736 self.processFlags = self.processFlags & (~PROCFLAG.DEFINE_PROCESS_CODE)
735
737
736 headerTuple = (self.size,
738 headerTuple = (self.size,
737 self.dtype,
739 self.dtype,
738 self.blockSize,
740 self.blockSize,
739 self.profilesPerBlock,
741 self.profilesPerBlock,
740 self.dataBlocksPerFile,
742 self.dataBlocksPerFile,
741 self.nWindows,
743 self.nWindows,
742 self.processFlags,
744 self.processFlags,
743 self.nCohInt,
745 self.nCohInt,
744 self.nIncohInt,
746 self.nIncohInt,
745 self.totalSpectra)
747 self.totalSpectra)
746
748
747 header = numpy.array(headerTuple, PROCESSING_STRUCTURE)
749 header = numpy.array(headerTuple, PROCESSING_STRUCTURE)
748 header.tofile(fp)
750 header.tofile(fp)
749
751
750 if self.nWindows != 0:
752 if self.nWindows != 0:
751 sampleWindowTuple = (
753 sampleWindowTuple = (
752 self.firstHeight, self.deltaHeight, self.samplesWin)
754 self.firstHeight, self.deltaHeight, self.samplesWin)
753 samplingWindow = numpy.array(sampleWindowTuple, SAMPLING_STRUCTURE)
755 samplingWindow = numpy.array(sampleWindowTuple, SAMPLING_STRUCTURE)
754 samplingWindow.tofile(fp)
756 samplingWindow.tofile(fp)
755
757
756 if self.totalSpectra != 0:
758 if self.totalSpectra != 0:
757 # spectraComb = numpy.array([],numpy.dtype('u1'))
759 # spectraComb = numpy.array([],numpy.dtype('u1'))
758 spectraComb = self.spectraComb
760 spectraComb = self.spectraComb
759 spectraComb.tofile(fp)
761 spectraComb.tofile(fp)
760
762
761 # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
763 # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
762 # nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba
764 # nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba
763 # nCode.tofile(fp)
765 # nCode.tofile(fp)
764 #
766 #
765 # nBaud = numpy.array([self.nBaud], numpy.dtype('u4'))
767 # nBaud = numpy.array([self.nBaud], numpy.dtype('u4'))
766 # nBaud.tofile(fp)
768 # nBaud.tofile(fp)
767 #
769 #
768 # code = self.code.reshape(self.nCode*self.nBaud)
770 # code = self.code.reshape(self.nCode*self.nBaud)
769 # code = code.astype(numpy.dtype('<f4'))
771 # code = code.astype(numpy.dtype('<f4'))
770 # code.tofile(fp)
772 # code.tofile(fp)
771
773
772 return 1
774 return 1
773
775
774 def get_size(self):
776 def get_size(self):
775
777
776 self.__size = 40 + 12 * self.nWindows + 2 * self.totalSpectra
778 self.__size = 40 + 12 * self.nWindows + 2 * self.totalSpectra
777
779
778 # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
780 # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
779 # self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.)
781 # self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.)
780 # self.__size += 4 + 4 + 4 * self.nCode * self.nBaud
782 # self.__size += 4 + 4 + 4 * self.nCode * self.nBaud
781
783
782 return self.__size
784 return self.__size
783
785
784 def set_size(self, value):
786 def set_size(self, value):
785
787
786 raise IOError, "size is a property and it cannot be set, just read"
788 raise IOError("size is a property and it cannot be set, just read")
787
789
788 return
790 return
789
791
790 size = property(get_size, set_size)
792 size = property(get_size, set_size)
791
793
792
794
793 class RCfunction:
795 class RCfunction:
794 NONE = 0
796 NONE = 0
795 FLIP = 1
797 FLIP = 1
796 CODE = 2
798 CODE = 2
797 SAMPLING = 3
799 SAMPLING = 3
798 LIN6DIV256 = 4
800 LIN6DIV256 = 4
799 SYNCHRO = 5
801 SYNCHRO = 5
800
802
801
803
802 class nCodeType:
804 class nCodeType:
803 NONE = 0
805 NONE = 0
804 USERDEFINE = 1
806 USERDEFINE = 1
805 BARKER2 = 2
807 BARKER2 = 2
806 BARKER3 = 3
808 BARKER3 = 3
807 BARKER4 = 4
809 BARKER4 = 4
808 BARKER5 = 5
810 BARKER5 = 5
809 BARKER7 = 6
811 BARKER7 = 6
810 BARKER11 = 7
812 BARKER11 = 7
811 BARKER13 = 8
813 BARKER13 = 8
812 AC128 = 9
814 AC128 = 9
813 COMPLEMENTARYCODE2 = 10
815 COMPLEMENTARYCODE2 = 10
814 COMPLEMENTARYCODE4 = 11
816 COMPLEMENTARYCODE4 = 11
815 COMPLEMENTARYCODE8 = 12
817 COMPLEMENTARYCODE8 = 12
816 COMPLEMENTARYCODE16 = 13
818 COMPLEMENTARYCODE16 = 13
817 COMPLEMENTARYCODE32 = 14
819 COMPLEMENTARYCODE32 = 14
818 COMPLEMENTARYCODE64 = 15
820 COMPLEMENTARYCODE64 = 15
819 COMPLEMENTARYCODE128 = 16
821 COMPLEMENTARYCODE128 = 16
820 CODE_BINARY28 = 17
822 CODE_BINARY28 = 17
821
823
822
824
823 class PROCFLAG:
825 class PROCFLAG:
824
826
825 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
827 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
826 DECODE_DATA = numpy.uint32(0x00000002)
828 DECODE_DATA = numpy.uint32(0x00000002)
827 SPECTRA_CALC = numpy.uint32(0x00000004)
829 SPECTRA_CALC = numpy.uint32(0x00000004)
828 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
830 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
829 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
831 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
830 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
832 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
831
833
832 DATATYPE_CHAR = numpy.uint32(0x00000040)
834 DATATYPE_CHAR = numpy.uint32(0x00000040)
833 DATATYPE_SHORT = numpy.uint32(0x00000080)
835 DATATYPE_SHORT = numpy.uint32(0x00000080)
834 DATATYPE_LONG = numpy.uint32(0x00000100)
836 DATATYPE_LONG = numpy.uint32(0x00000100)
835 DATATYPE_INT64 = numpy.uint32(0x00000200)
837 DATATYPE_INT64 = numpy.uint32(0x00000200)
836 DATATYPE_FLOAT = numpy.uint32(0x00000400)
838 DATATYPE_FLOAT = numpy.uint32(0x00000400)
837 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
839 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
838
840
839 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
841 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
840 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
842 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
841 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
843 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
842
844
843 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
845 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
844 DEFLIP_DATA = numpy.uint32(0x00010000)
846 DEFLIP_DATA = numpy.uint32(0x00010000)
845 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
847 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
846
848
847 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
849 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
848 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
850 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
849 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
851 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
850 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
852 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
851 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
853 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
852
854
853 EXP_NAME_ESP = numpy.uint32(0x00200000)
855 EXP_NAME_ESP = numpy.uint32(0x00200000)
854 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
856 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
855
857
856 OPERATION_MASK = numpy.uint32(0x0000003F)
858 OPERATION_MASK = numpy.uint32(0x0000003F)
857 DATATYPE_MASK = numpy.uint32(0x00000FC0)
859 DATATYPE_MASK = numpy.uint32(0x00000FC0)
858 DATAARRANGE_MASK = numpy.uint32(0x00007000)
860 DATAARRANGE_MASK = numpy.uint32(0x00007000)
859 ACQ_SYS_MASK = numpy.uint32(0x001C0000)
861 ACQ_SYS_MASK = numpy.uint32(0x001C0000)
860
862
861
863
862 dtype0 = numpy.dtype([('real', '<i1'), ('imag', '<i1')])
864 dtype0 = numpy.dtype([('real', '<i1'), ('imag', '<i1')])
863 dtype1 = numpy.dtype([('real', '<i2'), ('imag', '<i2')])
865 dtype1 = numpy.dtype([('real', '<i2'), ('imag', '<i2')])
864 dtype2 = numpy.dtype([('real', '<i4'), ('imag', '<i4')])
866 dtype2 = numpy.dtype([('real', '<i4'), ('imag', '<i4')])
865 dtype3 = numpy.dtype([('real', '<i8'), ('imag', '<i8')])
867 dtype3 = numpy.dtype([('real', '<i8'), ('imag', '<i8')])
866 dtype4 = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
868 dtype4 = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
867 dtype5 = numpy.dtype([('real', '<f8'), ('imag', '<f8')])
869 dtype5 = numpy.dtype([('real', '<f8'), ('imag', '<f8')])
868
870
869 NUMPY_DTYPE_LIST = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
871 NUMPY_DTYPE_LIST = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
870
872
871 PROCFLAG_DTYPE_LIST = [PROCFLAG.DATATYPE_CHAR,
873 PROCFLAG_DTYPE_LIST = [PROCFLAG.DATATYPE_CHAR,
872 PROCFLAG.DATATYPE_SHORT,
874 PROCFLAG.DATATYPE_SHORT,
873 PROCFLAG.DATATYPE_LONG,
875 PROCFLAG.DATATYPE_LONG,
874 PROCFLAG.DATATYPE_INT64,
876 PROCFLAG.DATATYPE_INT64,
875 PROCFLAG.DATATYPE_FLOAT,
877 PROCFLAG.DATATYPE_FLOAT,
876 PROCFLAG.DATATYPE_DOUBLE]
878 PROCFLAG.DATATYPE_DOUBLE]
877
879
878 DTYPE_WIDTH = [1, 2, 4, 8, 4, 8]
880 DTYPE_WIDTH = [1, 2, 4, 8, 4, 8]
879
881
880
882
881 def get_dtype_index(numpy_dtype):
883 def get_dtype_index(numpy_dtype):
882
884
883 index = None
885 index = None
884
886
885 for i in range(len(NUMPY_DTYPE_LIST)):
887 for i in range(len(NUMPY_DTYPE_LIST)):
886 if numpy_dtype == NUMPY_DTYPE_LIST[i]:
888 if numpy_dtype == NUMPY_DTYPE_LIST[i]:
887 index = i
889 index = i
888 break
890 break
889
891
890 return index
892 return index
891
893
892
894
893 def get_numpy_dtype(index):
895 def get_numpy_dtype(index):
894
896
895 return NUMPY_DTYPE_LIST[index]
897 return NUMPY_DTYPE_LIST[index]
896
898
897
899
898 def get_procflag_dtype(index):
900 def get_procflag_dtype(index):
899
901
900 return PROCFLAG_DTYPE_LIST[index]
902 return PROCFLAG_DTYPE_LIST[index]
901
903
902
904
903 def get_dtype_width(index):
905 def get_dtype_width(index):
904
906
905 return DTYPE_WIDTH[index]
907 return DTYPE_WIDTH[index] No newline at end of file
@@ -1,7 +1,7
1 from jroplot_voltage import *
1 from .jroplot_voltage import *
2 from jroplot_spectra import *
2 from .jroplot_spectra import *
3 from jroplot_heispectra import *
3 from .jroplot_heispectra import *
4 from jroplot_correlation import *
4 from .jroplot_correlation import *
5 from jroplot_parameters import *
5 from .jroplot_parameters import *
6 from jroplot_data import *
6 from .jroplot_data import *
7 from jroplotter import *
7 from .jroplotter import *
@@ -1,657 +1,657
1 import os
1 import os
2 import numpy
2 import numpy
3 import time, datetime
3 import time, datetime
4 import mpldriver
4 from schainpy.model.graphics 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 parameters = {}
64 parameters = {}
65 def __init__(self, **kwargs):
65 def __init__(self, **kwargs):
66
66
67 Operation.__init__(self, **kwargs)
67 Operation.__init__(self, **kwargs)
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 = 400
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 = int(xlen/self.__MAXNUMX) + 1
504 decimationx = int(xlen/self.__MAXNUMX) + 1
505 decimationy = int(ylen/self.__MAXNUMY) + 1
505 decimationy = int(ylen/self.__MAXNUMY) + 1
506
506
507
507
508 x_buffer = x#[::decimationx]
508 x_buffer = x#[::decimationx]
509 y_buffer = y#[::decimationy]
509 y_buffer = y#[::decimationy]
510 z_buffer = z#[::decimationx, ::decimationy]
510 z_buffer = z#[::decimationx, ::decimationy]
511 #===================================================
511 #===================================================
512
512
513 if self.__firsttime:
513 if self.__firsttime:
514
514
515 if xmin == None: xmin = numpy.nanmin(x)
515 if xmin == None: xmin = numpy.nanmin(x)
516 if xmax == None: xmax = numpy.nanmax(x)
516 if xmax == None: xmax = numpy.nanmax(x)
517 if ymin == None: ymin = numpy.nanmin(y)
517 if ymin == None: ymin = numpy.nanmin(y)
518 if ymax == None: ymax = numpy.nanmax(y)
518 if ymax == None: ymax = numpy.nanmax(y)
519 if zmin == None: zmin = numpy.nanmin(z)
519 if zmin == None: zmin = numpy.nanmin(z)
520 if zmax == None: zmax = numpy.nanmax(z)
520 if zmax == None: zmax = numpy.nanmax(z)
521
521
522
522
523 self.plot = self.__driver.createPcolor(self.ax, x_buffer,
523 self.plot = self.__driver.createPcolor(self.ax, x_buffer,
524 y_buffer,
524 y_buffer,
525 z_buffer,
525 z_buffer,
526 xmin, xmax,
526 xmin, xmax,
527 ymin, ymax,
527 ymin, ymax,
528 zmin, zmax,
528 zmin, zmax,
529 xlabel=xlabel,
529 xlabel=xlabel,
530 ylabel=ylabel,
530 ylabel=ylabel,
531 title=title,
531 title=title,
532 colormap=colormap,
532 colormap=colormap,
533 **kwargs)
533 **kwargs)
534
534
535 if self.xmin == None: self.xmin = xmin
535 if self.xmin == None: self.xmin = xmin
536 if self.xmax == None: self.xmax = xmax
536 if self.xmax == None: self.xmax = xmax
537 if self.ymin == None: self.ymin = ymin
537 if self.ymin == None: self.ymin = ymin
538 if self.ymax == None: self.ymax = ymax
538 if self.ymax == None: self.ymax = ymax
539 if self.zmin == None: self.zmin = zmin
539 if self.zmin == None: self.zmin = zmin
540 if self.zmax == None: self.zmax = zmax
540 if self.zmax == None: self.zmax = zmax
541
541
542 self.__firsttime = False
542 self.__firsttime = False
543 return
543 return
544
544
545 self.__driver.pcolor(self.plot,
545 self.__driver.pcolor(self.plot,
546 z_buffer,
546 z_buffer,
547 xlabel=xlabel,
547 xlabel=xlabel,
548 ylabel=ylabel,
548 ylabel=ylabel,
549 title=title)
549 title=title)
550
550
551 # self.__driver.pause()
551 # self.__driver.pause()
552
552
553 def pcolorbuffer(self, x, y, z,
553 def pcolorbuffer(self, x, y, z,
554 xmin=None, xmax=None,
554 xmin=None, xmax=None,
555 ymin=None, ymax=None,
555 ymin=None, ymax=None,
556 zmin=None, zmax=None,
556 zmin=None, zmax=None,
557 xlabel='', ylabel='',
557 xlabel='', ylabel='',
558 title='', rti = True, colormap='jet',
558 title='', rti = True, colormap='jet',
559 maxNumX = None, maxNumY = None,
559 maxNumX = None, maxNumY = None,
560 **kwargs):
560 **kwargs):
561
561
562 if maxNumX == None:
562 if maxNumX == None:
563 maxNumX = self.__MAXNUMTIME
563 maxNumX = self.__MAXNUMTIME
564
564
565 if maxNumY == None:
565 if maxNumY == None:
566 maxNumY = self.__MAXNUMY
566 maxNumY = self.__MAXNUMY
567
567
568 if self.__firsttime:
568 if self.__firsttime:
569 self.z_buffer = z
569 self.z_buffer = z
570 self.x_buffer = numpy.hstack((self.x_buffer, x))
570 self.x_buffer = numpy.hstack((self.x_buffer, x))
571
571
572 if xmin == None: xmin = numpy.nanmin(x)
572 if xmin == None: xmin = numpy.nanmin(x)
573 if xmax == None: xmax = numpy.nanmax(x)
573 if xmax == None: xmax = numpy.nanmax(x)
574 if ymin == None: ymin = numpy.nanmin(y)
574 if ymin == None: ymin = numpy.nanmin(y)
575 if ymax == None: ymax = numpy.nanmax(y)
575 if ymax == None: ymax = numpy.nanmax(y)
576 if zmin == None: zmin = numpy.nanmin(z)
576 if zmin == None: zmin = numpy.nanmin(z)
577 if zmax == None: zmax = numpy.nanmax(z)
577 if zmax == None: zmax = numpy.nanmax(z)
578
578
579 self.plot = self.__driver.createPcolor(self.ax, self.x_buffer, y, z,
579 self.plot = self.__driver.createPcolor(self.ax, self.x_buffer, y, z,
580 xmin, xmax,
580 xmin, xmax,
581 ymin, ymax,
581 ymin, ymax,
582 zmin, zmax,
582 zmin, zmax,
583 xlabel=xlabel,
583 xlabel=xlabel,
584 ylabel=ylabel,
584 ylabel=ylabel,
585 title=title,
585 title=title,
586 colormap=colormap,
586 colormap=colormap,
587 **kwargs)
587 **kwargs)
588
588
589 if self.xmin == None: self.xmin = xmin
589 if self.xmin == None: self.xmin = xmin
590 if self.xmax == None: self.xmax = xmax
590 if self.xmax == None: self.xmax = xmax
591 if self.ymin == None: self.ymin = ymin
591 if self.ymin == None: self.ymin = ymin
592 if self.ymax == None: self.ymax = ymax
592 if self.ymax == None: self.ymax = ymax
593 if self.zmin == None: self.zmin = zmin
593 if self.zmin == None: self.zmin = zmin
594 if self.zmax == None: self.zmax = zmax
594 if self.zmax == None: self.zmax = zmax
595
595
596 self.__firsttime = False
596 self.__firsttime = False
597 return
597 return
598
598
599 self.x_buffer = numpy.hstack((self.x_buffer[:-1], x[0], x[-1]))
599 self.x_buffer = numpy.hstack((self.x_buffer[:-1], x[0], x[-1]))
600 self.z_buffer = numpy.hstack((self.z_buffer, z))
600 self.z_buffer = numpy.hstack((self.z_buffer, z))
601 z_buffer = self.z_buffer.reshape(-1,len(y))
601 z_buffer = self.z_buffer.reshape(-1,len(y))
602
602
603 #Decimating data
603 #Decimating data
604 xlen = len(self.x_buffer)
604 xlen = len(self.x_buffer)
605 ylen = len(y)
605 ylen = len(y)
606
606
607 decimationx = int(xlen/maxNumX) + 1
607 decimationx = int(xlen/maxNumX) + 1
608 decimationy = int(ylen/maxNumY) + 1
608 decimationy = int(ylen/maxNumY) + 1
609
609
610 x_buffer = self.x_buffer#[::decimationx]
610 x_buffer = self.x_buffer#[::decimationx]
611 y_buffer = y#[::decimationy]
611 y_buffer = y#[::decimationy]
612 z_buffer = z_buffer#[::decimationx, ::decimationy]
612 z_buffer = z_buffer#[::decimationx, ::decimationy]
613 #===================================================
613 #===================================================
614
614
615 x_buffer, y_buffer, z_buffer = self.__fillGaps(x_buffer, y_buffer, z_buffer)
615 x_buffer, y_buffer, z_buffer = self.__fillGaps(x_buffer, y_buffer, z_buffer)
616
616
617 self.__driver.addpcolorbuffer(self.ax, x_buffer, y_buffer, z_buffer, self.zmin, self.zmax,
617 self.__driver.addpcolorbuffer(self.ax, x_buffer, y_buffer, z_buffer, self.zmin, self.zmax,
618 xlabel=xlabel,
618 xlabel=xlabel,
619 ylabel=ylabel,
619 ylabel=ylabel,
620 title=title,
620 title=title,
621 colormap=colormap)
621 colormap=colormap)
622
622
623 # self.__driver.pause()
623 # self.__driver.pause()
624
624
625 def polar(self, x, y,
625 def polar(self, x, y,
626 title='', xlabel='',ylabel='',**kwargs):
626 title='', xlabel='',ylabel='',**kwargs):
627
627
628 if self.__firsttime:
628 if self.__firsttime:
629 self.plot = self.__driver.createPolar(self.ax, x, y, title = title, xlabel = xlabel, ylabel = ylabel)
629 self.plot = self.__driver.createPolar(self.ax, x, y, title = title, xlabel = xlabel, ylabel = ylabel)
630 self.__firsttime = False
630 self.__firsttime = False
631 self.x_buffer = x
631 self.x_buffer = x
632 self.y_buffer = y
632 self.y_buffer = y
633 return
633 return
634
634
635 self.x_buffer = numpy.hstack((self.x_buffer,x))
635 self.x_buffer = numpy.hstack((self.x_buffer,x))
636 self.y_buffer = numpy.hstack((self.y_buffer,y))
636 self.y_buffer = numpy.hstack((self.y_buffer,y))
637 self.__driver.polar(self.plot, self.x_buffer, self.y_buffer, xlabel=xlabel,
637 self.__driver.polar(self.plot, self.x_buffer, self.y_buffer, xlabel=xlabel,
638 ylabel=ylabel,
638 ylabel=ylabel,
639 title=title)
639 title=title)
640
640
641 # self.__driver.pause()
641 # self.__driver.pause()
642
642
643 def __fillGaps(self, x_buffer, y_buffer, z_buffer):
643 def __fillGaps(self, x_buffer, y_buffer, z_buffer):
644
644
645 if x_buffer.shape[0] < 2:
645 if x_buffer.shape[0] < 2:
646 return x_buffer, y_buffer, z_buffer
646 return x_buffer, y_buffer, z_buffer
647
647
648 deltas = x_buffer[1:] - x_buffer[0:-1]
648 deltas = x_buffer[1:] - x_buffer[0:-1]
649 x_median = numpy.median(deltas)
649 x_median = numpy.median(deltas)
650
650
651 index = numpy.where(deltas > 5*x_median)
651 index = numpy.where(deltas > 5*x_median)
652
652
653 if len(index[0]) != 0:
653 if len(index[0]) != 0:
654 z_buffer[index[0],::] = self.__missing
654 z_buffer[index[0],::] = self.__missing
655 z_buffer = numpy.ma.masked_inside(z_buffer,0.99*self.__missing,1.01*self.__missing)
655 z_buffer = numpy.ma.masked_inside(z_buffer,0.99*self.__missing,1.01*self.__missing)
656
656
657 return x_buffer, y_buffer, z_buffer
657 return x_buffer, y_buffer, z_buffer No newline at end of file
@@ -1,187 +1,187
1 import os
1 import os
2 import datetime
2 import datetime
3 import numpy
3 import numpy
4 import copy
4 import copy
5 from schainpy.model import *
5 from schainpy.model import *
6 from figure import Figure, isRealtime
6 from .figure import Figure, isRealtime
7
7
8 class CorrelationPlot(Figure):
8 class CorrelationPlot(Figure):
9 isConfig = None
9 isConfig = None
10 __nsubplots = None
10 __nsubplots = None
11
11
12 WIDTHPROF = None
12 WIDTHPROF = None
13 HEIGHTPROF = None
13 HEIGHTPROF = None
14 PREFIX = 'corr'
14 PREFIX = 'corr'
15
15
16 def __init__(self, **kwargs):
16 def __init__(self, **kwargs):
17 Figure.__init__(self, **kwargs)
17 Figure.__init__(self, **kwargs)
18 self.isConfig = False
18 self.isConfig = False
19 self.__nsubplots = 1
19 self.__nsubplots = 1
20
20
21 self.WIDTH = 280
21 self.WIDTH = 280
22 self.HEIGHT = 250
22 self.HEIGHT = 250
23 self.WIDTHPROF = 120
23 self.WIDTHPROF = 120
24 self.HEIGHTPROF = 0
24 self.HEIGHTPROF = 0
25 self.counter_imagwr = 0
25 self.counter_imagwr = 0
26
26
27 self.PLOT_CODE = 1
27 self.PLOT_CODE = 1
28 self.FTP_WEI = None
28 self.FTP_WEI = None
29 self.EXP_CODE = None
29 self.EXP_CODE = None
30 self.SUB_EXP_CODE = None
30 self.SUB_EXP_CODE = None
31 self.PLOT_POS = None
31 self.PLOT_POS = None
32
32
33 def getSubplots(self):
33 def getSubplots(self):
34
34
35 ncol = int(numpy.sqrt(self.nplots)+0.9)
35 ncol = int(numpy.sqrt(self.nplots)+0.9)
36 nrow = int(self.nplots*1./ncol + 0.9)
36 nrow = int(self.nplots*1./ncol + 0.9)
37
37
38 return nrow, ncol
38 return nrow, ncol
39
39
40 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
40 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
41
41
42 showprofile = False
42 showprofile = False
43 self.__showprofile = showprofile
43 self.__showprofile = showprofile
44 self.nplots = nplots
44 self.nplots = nplots
45
45
46 ncolspan = 1
46 ncolspan = 1
47 colspan = 1
47 colspan = 1
48 if showprofile:
48 if showprofile:
49 ncolspan = 3
49 ncolspan = 3
50 colspan = 2
50 colspan = 2
51 self.__nsubplots = 2
51 self.__nsubplots = 2
52
52
53 self.createFigure(id = id,
53 self.createFigure(id = id,
54 wintitle = wintitle,
54 wintitle = wintitle,
55 widthplot = self.WIDTH + self.WIDTHPROF,
55 widthplot = self.WIDTH + self.WIDTHPROF,
56 heightplot = self.HEIGHT + self.HEIGHTPROF,
56 heightplot = self.HEIGHT + self.HEIGHTPROF,
57 show=show)
57 show=show)
58
58
59 nrow, ncol = self.getSubplots()
59 nrow, ncol = self.getSubplots()
60
60
61 counter = 0
61 counter = 0
62 for y in range(nrow):
62 for y in range(nrow):
63 for x in range(ncol):
63 for x in range(ncol):
64
64
65 if counter >= self.nplots:
65 if counter >= self.nplots:
66 break
66 break
67
67
68 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
68 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
69
69
70 if showprofile:
70 if showprofile:
71 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
71 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
72
72
73 counter += 1
73 counter += 1
74
74
75 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
75 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
76 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
76 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
77 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
77 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
78 server=None, folder=None, username=None, password=None,
78 server=None, folder=None, username=None, password=None,
79 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
79 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
80
80
81 """
81 """
82
82
83 Input:
83 Input:
84 dataOut :
84 dataOut :
85 id :
85 id :
86 wintitle :
86 wintitle :
87 channelList :
87 channelList :
88 showProfile :
88 showProfile :
89 xmin : None,
89 xmin : None,
90 xmax : None,
90 xmax : None,
91 ymin : None,
91 ymin : None,
92 ymax : None,
92 ymax : None,
93 zmin : None,
93 zmin : None,
94 zmax : None
94 zmax : None
95 """
95 """
96
96
97 if dataOut.flagNoData:
97 if dataOut.flagNoData:
98 return None
98 return None
99
99
100 if realtime:
100 if realtime:
101 if not(isRealtime(utcdatatime = dataOut.utctime)):
101 if not(isRealtime(utcdatatime = dataOut.utctime)):
102 print 'Skipping this plot function'
102 print('Skipping this plot function')
103 return
103 return
104
104
105 if channelList == None:
105 if channelList == None:
106 channelIndexList = dataOut.channelIndexList
106 channelIndexList = dataOut.channelIndexList
107 else:
107 else:
108 channelIndexList = []
108 channelIndexList = []
109 for channel in channelList:
109 for channel in channelList:
110 if channel not in dataOut.channelList:
110 if channel not in dataOut.channelList:
111 raise ValueError, "Channel %d is not in dataOut.channelList"
111 raise ValueError("Channel %d is not in dataOut.channelList")
112 channelIndexList.append(dataOut.channelList.index(channel))
112 channelIndexList.append(dataOut.channelList.index(channel))
113
113
114 factor = dataOut.normFactor
114 factor = dataOut.normFactor
115 lenfactor = factor.shape[1]
115 lenfactor = factor.shape[1]
116 x = dataOut.getLagTRange(1)
116 x = dataOut.getLagTRange(1)
117 y = dataOut.getHeiRange()
117 y = dataOut.getHeiRange()
118
118
119 z = copy.copy(dataOut.data_corr[:,:,0,:])
119 z = copy.copy(dataOut.data_corr[:,:,0,:])
120 for i in range(dataOut.data_corr.shape[0]):
120 for i in range(dataOut.data_corr.shape[0]):
121 z[i,:,:] = z[i,:,:]/factor[i,:]
121 z[i,:,:] = z[i,:,:]/factor[i,:]
122 zdB = numpy.abs(z)
122 zdB = numpy.abs(z)
123
123
124 avg = numpy.average(z, axis=1)
124 avg = numpy.average(z, axis=1)
125 # avg = numpy.nanmean(z, axis=1)
125 # avg = numpy.nanmean(z, axis=1)
126 # noise = dataOut.noise/factor
126 # noise = dataOut.noise/factor
127
127
128 #thisDatetime = dataOut.datatime
128 #thisDatetime = dataOut.datatime
129 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
129 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
130 title = wintitle + " Correlation"
130 title = wintitle + " Correlation"
131 xlabel = "Lag T (s)"
131 xlabel = "Lag T (s)"
132 ylabel = "Range (Km)"
132 ylabel = "Range (Km)"
133
133
134 if not self.isConfig:
134 if not self.isConfig:
135
135
136 nplots = dataOut.data_corr.shape[0]
136 nplots = dataOut.data_corr.shape[0]
137
137
138 self.setup(id=id,
138 self.setup(id=id,
139 nplots=nplots,
139 nplots=nplots,
140 wintitle=wintitle,
140 wintitle=wintitle,
141 showprofile=showprofile,
141 showprofile=showprofile,
142 show=show)
142 show=show)
143
143
144 if xmin == None: xmin = numpy.nanmin(x)
144 if xmin == None: xmin = numpy.nanmin(x)
145 if xmax == None: xmax = numpy.nanmax(x)
145 if xmax == None: xmax = numpy.nanmax(x)
146 if ymin == None: ymin = numpy.nanmin(y)
146 if ymin == None: ymin = numpy.nanmin(y)
147 if ymax == None: ymax = numpy.nanmax(y)
147 if ymax == None: ymax = numpy.nanmax(y)
148 if zmin == None: zmin = 0
148 if zmin == None: zmin = 0
149 if zmax == None: zmax = 1
149 if zmax == None: zmax = 1
150
150
151 self.FTP_WEI = ftp_wei
151 self.FTP_WEI = ftp_wei
152 self.EXP_CODE = exp_code
152 self.EXP_CODE = exp_code
153 self.SUB_EXP_CODE = sub_exp_code
153 self.SUB_EXP_CODE = sub_exp_code
154 self.PLOT_POS = plot_pos
154 self.PLOT_POS = plot_pos
155
155
156 self.isConfig = True
156 self.isConfig = True
157
157
158 self.setWinTitle(title)
158 self.setWinTitle(title)
159
159
160 for i in range(self.nplots):
160 for i in range(self.nplots):
161 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
161 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
162 title = "Channel %d and %d: : %s" %(dataOut.pairsList[i][0],dataOut.pairsList[i][1] , str_datetime)
162 title = "Channel %d and %d: : %s" %(dataOut.pairsList[i][0],dataOut.pairsList[i][1] , str_datetime)
163 axes = self.axesList[i*self.__nsubplots]
163 axes = self.axesList[i*self.__nsubplots]
164 axes.pcolor(x, y, zdB[i,:,:],
164 axes.pcolor(x, y, zdB[i,:,:],
165 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
165 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
166 xlabel=xlabel, ylabel=ylabel, title=title,
166 xlabel=xlabel, ylabel=ylabel, title=title,
167 ticksize=9, cblabel='')
167 ticksize=9, cblabel='')
168
168
169 # if self.__showprofile:
169 # if self.__showprofile:
170 # axes = self.axesList[i*self.__nsubplots +1]
170 # axes = self.axesList[i*self.__nsubplots +1]
171 # axes.pline(avgdB[i], y,
171 # axes.pline(avgdB[i], y,
172 # xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
172 # xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
173 # xlabel='dB', ylabel='', title='',
173 # xlabel='dB', ylabel='', title='',
174 # ytick_visible=False,
174 # ytick_visible=False,
175 # grid='x')
175 # grid='x')
176 #
176 #
177 # noiseline = numpy.repeat(noisedB[i], len(y))
177 # noiseline = numpy.repeat(noisedB[i], len(y))
178 # axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
178 # axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
179
179
180 self.draw()
180 self.draw()
181
181
182 self.save(figpath=figpath,
182 self.save(figpath=figpath,
183 figfile=figfile,
183 figfile=figfile,
184 save=save,
184 save=save,
185 ftp=ftp,
185 ftp=ftp,
186 wr_period=wr_period,
186 wr_period=wr_period,
187 thisDatetime=thisDatetime)
187 thisDatetime=thisDatetime) No newline at end of file
@@ -1,1148 +1,1148
1
1
2 import os
2 import os
3 import time
3 import time
4 import glob
4 import glob
5 import datetime
5 import datetime
6 from multiprocessing import Process
6 from multiprocessing import Process
7
7
8 import zmq
8 import zmq
9 import numpy
9 import numpy
10 import matplotlib
10 import matplotlib
11 import matplotlib.pyplot as plt
11 import matplotlib.pyplot as plt
12 from matplotlib.patches import Polygon
12 from matplotlib.patches import Polygon
13 from mpl_toolkits.axes_grid1 import make_axes_locatable
13 from mpl_toolkits.axes_grid1 import make_axes_locatable
14 from matplotlib.ticker import FuncFormatter, LinearLocator, MultipleLocator
14 from matplotlib.ticker import FuncFormatter, LinearLocator, MultipleLocator
15
15
16 from schainpy.model.proc.jroproc_base import Operation
16 from schainpy.model.proc.jroproc_base import Operation
17 from schainpy.utils import log
17 from schainpy.utils import log
18
18
19 jet_values = matplotlib.pyplot.get_cmap('jet', 100)(numpy.arange(100))[10:90]
19 jet_values = matplotlib.pyplot.get_cmap('jet', 100)(numpy.arange(100))[10:90]
20 blu_values = matplotlib.pyplot.get_cmap(
20 blu_values = matplotlib.pyplot.get_cmap(
21 'seismic_r', 20)(numpy.arange(20))[10:15]
21 'seismic_r', 20)(numpy.arange(20))[10:15]
22 ncmap = matplotlib.colors.LinearSegmentedColormap.from_list(
22 ncmap = matplotlib.colors.LinearSegmentedColormap.from_list(
23 'jro', numpy.vstack((blu_values, jet_values)))
23 'jro', numpy.vstack((blu_values, jet_values)))
24 matplotlib.pyplot.register_cmap(cmap=ncmap)
24 matplotlib.pyplot.register_cmap(cmap=ncmap)
25
25
26 CMAPS = [plt.get_cmap(s) for s in ('jro', 'jet', 'viridis', 'plasma', 'inferno', 'Greys', 'seismic', 'bwr', 'coolwarm')]
26 CMAPS = [plt.get_cmap(s) for s in ('jro', 'jet', 'viridis', 'plasma', 'inferno', 'Greys', 'seismic', 'bwr', 'coolwarm')]
27
27
28 EARTH_RADIUS = 6.3710e3
28 EARTH_RADIUS = 6.3710e3
29
29
30 def ll2xy(lat1, lon1, lat2, lon2):
30 def ll2xy(lat1, lon1, lat2, lon2):
31
31
32 p = 0.017453292519943295
32 p = 0.017453292519943295
33 a = 0.5 - numpy.cos((lat2 - lat1) * p)/2 + numpy.cos(lat1 * p) * numpy.cos(lat2 * p) * (1 - numpy.cos((lon2 - lon1) * p)) / 2
33 a = 0.5 - numpy.cos((lat2 - lat1) * p)/2 + numpy.cos(lat1 * p) * numpy.cos(lat2 * p) * (1 - numpy.cos((lon2 - lon1) * p)) / 2
34 r = 12742 * numpy.arcsin(numpy.sqrt(a))
34 r = 12742 * numpy.arcsin(numpy.sqrt(a))
35 theta = numpy.arctan2(numpy.sin((lon2-lon1)*p)*numpy.cos(lat2*p), numpy.cos(lat1*p)*numpy.sin(lat2*p)-numpy.sin(lat1*p)*numpy.cos(lat2*p)*numpy.cos((lon2-lon1)*p))
35 theta = numpy.arctan2(numpy.sin((lon2-lon1)*p)*numpy.cos(lat2*p), numpy.cos(lat1*p)*numpy.sin(lat2*p)-numpy.sin(lat1*p)*numpy.cos(lat2*p)*numpy.cos((lon2-lon1)*p))
36 theta = -theta + numpy.pi/2
36 theta = -theta + numpy.pi/2
37 return r*numpy.cos(theta), r*numpy.sin(theta)
37 return r*numpy.cos(theta), r*numpy.sin(theta)
38
38
39 def km2deg(km):
39 def km2deg(km):
40 '''
40 '''
41 Convert distance in km to degrees
41 Convert distance in km to degrees
42 '''
42 '''
43
43
44 return numpy.rad2deg(km/EARTH_RADIUS)
44 return numpy.rad2deg(km/EARTH_RADIUS)
45
45
46 def figpause(interval):
46 def figpause(interval):
47 backend = plt.rcParams['backend']
47 backend = plt.rcParams['backend']
48 if backend in matplotlib.rcsetup.interactive_bk:
48 if backend in matplotlib.rcsetup.interactive_bk:
49 figManager = matplotlib._pylab_helpers.Gcf.get_active()
49 figManager = matplotlib._pylab_helpers.Gcf.get_active()
50 if figManager is not None:
50 if figManager is not None:
51 canvas = figManager.canvas
51 canvas = figManager.canvas
52 if canvas.figure.stale:
52 if canvas.figure.stale:
53 canvas.draw()
53 canvas.draw()
54 try:
54 try:
55 canvas.start_event_loop(interval)
55 canvas.start_event_loop(interval)
56 except:
56 except:
57 pass
57 pass
58 return
58 return
59
59
60 def popup(message):
60 def popup(message):
61 '''
61 '''
62 '''
62 '''
63
63
64 fig = plt.figure(figsize=(12, 8), facecolor='r')
64 fig = plt.figure(figsize=(12, 8), facecolor='r')
65 text = '\n'.join([s.strip() for s in message.split(':')])
65 text = '\n'.join([s.strip() for s in message.split(':')])
66 fig.text(0.01, 0.5, text, ha='left', va='center', size='20', weight='heavy', color='w')
66 fig.text(0.01, 0.5, text, ha='left', va='center', size='20', weight='heavy', color='w')
67 fig.show()
67 fig.show()
68 figpause(1000)
68 figpause(1000)
69
69
70
70
71 class PlotData(Operation, Process):
71 class PlotData(Operation, Process):
72 '''
72 '''
73 Base class for Schain plotting operations
73 Base class for Schain plotting operations
74 '''
74 '''
75
75
76 CODE = 'Figure'
76 CODE = 'Figure'
77 colormap = 'jro'
77 colormap = 'jro'
78 bgcolor = 'white'
78 bgcolor = 'white'
79 CONFLATE = False
79 CONFLATE = False
80 __missing = 1E30
80 __missing = 1E30
81
81
82 __attrs__ = ['show', 'save', 'xmin', 'xmax', 'ymin', 'ymax', 'zmin', 'zmax',
82 __attrs__ = ['show', 'save', 'xmin', 'xmax', 'ymin', 'ymax', 'zmin', 'zmax',
83 'zlimits', 'xlabel', 'ylabel', 'xaxis','cb_label', 'title',
83 'zlimits', 'xlabel', 'ylabel', 'xaxis','cb_label', 'title',
84 'colorbar', 'bgcolor', 'width', 'height', 'localtime', 'oneFigure',
84 'colorbar', 'bgcolor', 'width', 'height', 'localtime', 'oneFigure',
85 'showprofile', 'decimation', 'ftp']
85 'showprofile', 'decimation', 'ftp']
86
86
87 def __init__(self, **kwargs):
87 def __init__(self, **kwargs):
88
88
89 Operation.__init__(self, plot=True, **kwargs)
89 Operation.__init__(self, plot=True, **kwargs)
90 Process.__init__(self)
90 Process.__init__(self)
91
91
92 self.kwargs['code'] = self.CODE
92 self.kwargs['code'] = self.CODE
93 self.mp = False
93 self.mp = False
94 self.data = None
94 self.data = None
95 self.isConfig = False
95 self.isConfig = False
96 self.figures = []
96 self.figures = []
97 self.axes = []
97 self.axes = []
98 self.cb_axes = []
98 self.cb_axes = []
99 self.localtime = kwargs.pop('localtime', True)
99 self.localtime = kwargs.pop('localtime', True)
100 self.show = kwargs.get('show', True)
100 self.show = kwargs.get('show', True)
101 self.save = kwargs.get('save', False)
101 self.save = kwargs.get('save', False)
102 self.ftp = kwargs.get('ftp', False)
102 self.ftp = kwargs.get('ftp', False)
103 self.colormap = kwargs.get('colormap', self.colormap)
103 self.colormap = kwargs.get('colormap', self.colormap)
104 self.colormap_coh = kwargs.get('colormap_coh', 'jet')
104 self.colormap_coh = kwargs.get('colormap_coh', 'jet')
105 self.colormap_phase = kwargs.get('colormap_phase', 'RdBu_r')
105 self.colormap_phase = kwargs.get('colormap_phase', 'RdBu_r')
106 self.colormaps = kwargs.get('colormaps', None)
106 self.colormaps = kwargs.get('colormaps', None)
107 self.bgcolor = kwargs.get('bgcolor', self.bgcolor)
107 self.bgcolor = kwargs.get('bgcolor', self.bgcolor)
108 self.showprofile = kwargs.get('showprofile', False)
108 self.showprofile = kwargs.get('showprofile', False)
109 self.title = kwargs.get('wintitle', self.CODE.upper())
109 self.title = kwargs.get('wintitle', self.CODE.upper())
110 self.cb_label = kwargs.get('cb_label', None)
110 self.cb_label = kwargs.get('cb_label', None)
111 self.cb_labels = kwargs.get('cb_labels', None)
111 self.cb_labels = kwargs.get('cb_labels', None)
112 self.labels = kwargs.get('labels', None)
112 self.labels = kwargs.get('labels', None)
113 self.xaxis = kwargs.get('xaxis', 'frequency')
113 self.xaxis = kwargs.get('xaxis', 'frequency')
114 self.zmin = kwargs.get('zmin', None)
114 self.zmin = kwargs.get('zmin', None)
115 self.zmax = kwargs.get('zmax', None)
115 self.zmax = kwargs.get('zmax', None)
116 self.zlimits = kwargs.get('zlimits', None)
116 self.zlimits = kwargs.get('zlimits', None)
117 self.xmin = kwargs.get('xmin', None)
117 self.xmin = kwargs.get('xmin', None)
118 self.xmax = kwargs.get('xmax', None)
118 self.xmax = kwargs.get('xmax', None)
119 self.xrange = kwargs.get('xrange', 24)
119 self.xrange = kwargs.get('xrange', 24)
120 self.xscale = kwargs.get('xscale', None)
120 self.xscale = kwargs.get('xscale', None)
121 self.ymin = kwargs.get('ymin', None)
121 self.ymin = kwargs.get('ymin', None)
122 self.ymax = kwargs.get('ymax', None)
122 self.ymax = kwargs.get('ymax', None)
123 self.yscale = kwargs.get('yscale', None)
123 self.yscale = kwargs.get('yscale', None)
124 self.xlabel = kwargs.get('xlabel', None)
124 self.xlabel = kwargs.get('xlabel', None)
125 self.decimation = kwargs.get('decimation', None)
125 self.decimation = kwargs.get('decimation', None)
126 self.showSNR = kwargs.get('showSNR', False)
126 self.showSNR = kwargs.get('showSNR', False)
127 self.oneFigure = kwargs.get('oneFigure', True)
127 self.oneFigure = kwargs.get('oneFigure', True)
128 self.width = kwargs.get('width', None)
128 self.width = kwargs.get('width', None)
129 self.height = kwargs.get('height', None)
129 self.height = kwargs.get('height', None)
130 self.colorbar = kwargs.get('colorbar', True)
130 self.colorbar = kwargs.get('colorbar', True)
131 self.factors = kwargs.get('factors', [1, 1, 1, 1, 1, 1, 1, 1])
131 self.factors = kwargs.get('factors', [1, 1, 1, 1, 1, 1, 1, 1])
132 self.channels = kwargs.get('channels', None)
132 self.channels = kwargs.get('channels', None)
133 self.titles = kwargs.get('titles', [])
133 self.titles = kwargs.get('titles', [])
134 self.polar = False
134 self.polar = False
135 self.grid = kwargs.get('grid', False)
135 self.grid = kwargs.get('grid', False)
136
136
137 def __fmtTime(self, x, pos):
137 def __fmtTime(self, x, pos):
138 '''
138 '''
139 '''
139 '''
140
140
141 return '{}'.format(self.getDateTime(x).strftime('%H:%M'))
141 return '{}'.format(self.getDateTime(x).strftime('%H:%M'))
142
142
143 def __setup(self):
143 def __setup(self):
144 '''
144 '''
145 Common setup for all figures, here figures and axes are created
145 Common setup for all figures, here figures and axes are created
146 '''
146 '''
147
147
148 if self.CODE not in self.data:
148 if self.CODE not in self.data:
149 raise ValueError(log.error('Missing data for {}'.format(self.CODE),
149 raise ValueError(log.error('Missing data for {}'.format(self.CODE),
150 self.name))
150 self.name))
151
151
152 self.setup()
152 self.setup()
153
153
154 self.time_label = 'LT' if self.localtime else 'UTC'
154 self.time_label = 'LT' if self.localtime else 'UTC'
155 if self.data.localtime:
155 if self.data.localtime:
156 self.getDateTime = datetime.datetime.fromtimestamp
156 self.getDateTime = datetime.datetime.fromtimestamp
157 else:
157 else:
158 self.getDateTime = datetime.datetime.utcfromtimestamp
158 self.getDateTime = datetime.datetime.utcfromtimestamp
159
159
160 if self.width is None:
160 if self.width is None:
161 self.width = 8
161 self.width = 8
162
162
163 self.figures = []
163 self.figures = []
164 self.axes = []
164 self.axes = []
165 self.cb_axes = []
165 self.cb_axes = []
166 self.pf_axes = []
166 self.pf_axes = []
167 self.cmaps = []
167 self.cmaps = []
168
168
169 size = '15%' if self.ncols == 1 else '30%'
169 size = '15%' if self.ncols == 1 else '30%'
170 pad = '4%' if self.ncols == 1 else '8%'
170 pad = '4%' if self.ncols == 1 else '8%'
171
171
172 if self.oneFigure:
172 if self.oneFigure:
173 if self.height is None:
173 if self.height is None:
174 self.height = 1.4 * self.nrows + 1
174 self.height = 1.4 * self.nrows + 1
175 fig = plt.figure(figsize=(self.width, self.height),
175 fig = plt.figure(figsize=(self.width, self.height),
176 edgecolor='k',
176 edgecolor='k',
177 facecolor='w')
177 facecolor='w')
178 self.figures.append(fig)
178 self.figures.append(fig)
179 for n in range(self.nplots):
179 for n in range(self.nplots):
180 ax = fig.add_subplot(self.nrows, self.ncols,
180 ax = fig.add_subplot(self.nrows, self.ncols,
181 n + 1, polar=self.polar)
181 n + 1, polar=self.polar)
182 ax.tick_params(labelsize=8)
182 ax.tick_params(labelsize=8)
183 ax.firsttime = True
183 ax.firsttime = True
184 ax.index = 0
184 ax.index = 0
185 ax.press = None
185 ax.press = None
186 self.axes.append(ax)
186 self.axes.append(ax)
187 if self.showprofile:
187 if self.showprofile:
188 cax = self.__add_axes(ax, size=size, pad=pad)
188 cax = self.__add_axes(ax, size=size, pad=pad)
189 cax.tick_params(labelsize=8)
189 cax.tick_params(labelsize=8)
190 self.pf_axes.append(cax)
190 self.pf_axes.append(cax)
191 else:
191 else:
192 if self.height is None:
192 if self.height is None:
193 self.height = 3
193 self.height = 3
194 for n in range(self.nplots):
194 for n in range(self.nplots):
195 fig = plt.figure(figsize=(self.width, self.height),
195 fig = plt.figure(figsize=(self.width, self.height),
196 edgecolor='k',
196 edgecolor='k',
197 facecolor='w')
197 facecolor='w')
198 ax = fig.add_subplot(1, 1, 1, polar=self.polar)
198 ax = fig.add_subplot(1, 1, 1, polar=self.polar)
199 ax.tick_params(labelsize=8)
199 ax.tick_params(labelsize=8)
200 ax.firsttime = True
200 ax.firsttime = True
201 ax.index = 0
201 ax.index = 0
202 ax.press = None
202 ax.press = None
203 self.figures.append(fig)
203 self.figures.append(fig)
204 self.axes.append(ax)
204 self.axes.append(ax)
205 if self.showprofile:
205 if self.showprofile:
206 cax = self.__add_axes(ax, size=size, pad=pad)
206 cax = self.__add_axes(ax, size=size, pad=pad)
207 cax.tick_params(labelsize=8)
207 cax.tick_params(labelsize=8)
208 self.pf_axes.append(cax)
208 self.pf_axes.append(cax)
209
209
210 for n in range(self.nrows):
210 for n in range(self.nrows):
211 if self.colormaps is not None:
211 if self.colormaps is not None:
212 cmap = plt.get_cmap(self.colormaps[n])
212 cmap = plt.get_cmap(self.colormaps[n])
213 else:
213 else:
214 cmap = plt.get_cmap(self.colormap)
214 cmap = plt.get_cmap(self.colormap)
215 cmap.set_bad(self.bgcolor, 1.)
215 cmap.set_bad(self.bgcolor, 1.)
216 self.cmaps.append(cmap)
216 self.cmaps.append(cmap)
217
217
218 for fig in self.figures:
218 for fig in self.figures:
219 fig.canvas.mpl_connect('key_press_event', self.OnKeyPress)
219 fig.canvas.mpl_connect('key_press_event', self.OnKeyPress)
220 fig.canvas.mpl_connect('scroll_event', self.OnBtnScroll)
220 fig.canvas.mpl_connect('scroll_event', self.OnBtnScroll)
221 fig.canvas.mpl_connect('button_press_event', self.onBtnPress)
221 fig.canvas.mpl_connect('button_press_event', self.onBtnPress)
222 fig.canvas.mpl_connect('motion_notify_event', self.onMotion)
222 fig.canvas.mpl_connect('motion_notify_event', self.onMotion)
223 fig.canvas.mpl_connect('button_release_event', self.onBtnRelease)
223 fig.canvas.mpl_connect('button_release_event', self.onBtnRelease)
224 if self.show:
224 if self.show:
225 fig.show()
225 fig.show()
226
226
227 def OnKeyPress(self, event):
227 def OnKeyPress(self, event):
228 '''
228 '''
229 Event for pressing keys (up, down) change colormap
229 Event for pressing keys (up, down) change colormap
230 '''
230 '''
231 ax = event.inaxes
231 ax = event.inaxes
232 if ax in self.axes:
232 if ax in self.axes:
233 if event.key == 'down':
233 if event.key == 'down':
234 ax.index += 1
234 ax.index += 1
235 elif event.key == 'up':
235 elif event.key == 'up':
236 ax.index -= 1
236 ax.index -= 1
237 if ax.index < 0:
237 if ax.index < 0:
238 ax.index = len(CMAPS) - 1
238 ax.index = len(CMAPS) - 1
239 elif ax.index == len(CMAPS):
239 elif ax.index == len(CMAPS):
240 ax.index = 0
240 ax.index = 0
241 cmap = CMAPS[ax.index]
241 cmap = CMAPS[ax.index]
242 ax.cbar.set_cmap(cmap)
242 ax.cbar.set_cmap(cmap)
243 ax.cbar.draw_all()
243 ax.cbar.draw_all()
244 ax.plt.set_cmap(cmap)
244 ax.plt.set_cmap(cmap)
245 ax.cbar.patch.figure.canvas.draw()
245 ax.cbar.patch.figure.canvas.draw()
246 self.colormap = cmap.name
246 self.colormap = cmap.name
247
247
248 def OnBtnScroll(self, event):
248 def OnBtnScroll(self, event):
249 '''
249 '''
250 Event for scrolling, scale figure
250 Event for scrolling, scale figure
251 '''
251 '''
252 cb_ax = event.inaxes
252 cb_ax = event.inaxes
253 if cb_ax in [ax.cbar.ax for ax in self.axes if ax.cbar]:
253 if cb_ax in [ax.cbar.ax for ax in self.axes if ax.cbar]:
254 ax = [ax for ax in self.axes if cb_ax == ax.cbar.ax][0]
254 ax = [ax for ax in self.axes if cb_ax == ax.cbar.ax][0]
255 pt = ax.cbar.ax.bbox.get_points()[:, 1]
255 pt = ax.cbar.ax.bbox.get_points()[:, 1]
256 nrm = ax.cbar.norm
256 nrm = ax.cbar.norm
257 vmin, vmax, p0, p1, pS = (
257 vmin, vmax, p0, p1, pS = (
258 nrm.vmin, nrm.vmax, pt[0], pt[1], event.y)
258 nrm.vmin, nrm.vmax, pt[0], pt[1], event.y)
259 scale = 2 if event.step == 1 else 0.5
259 scale = 2 if event.step == 1 else 0.5
260 point = vmin + (vmax - vmin) / (p1 - p0) * (pS - p0)
260 point = vmin + (vmax - vmin) / (p1 - p0) * (pS - p0)
261 ax.cbar.norm.vmin = point - scale * (point - vmin)
261 ax.cbar.norm.vmin = point - scale * (point - vmin)
262 ax.cbar.norm.vmax = point - scale * (point - vmax)
262 ax.cbar.norm.vmax = point - scale * (point - vmax)
263 ax.plt.set_norm(ax.cbar.norm)
263 ax.plt.set_norm(ax.cbar.norm)
264 ax.cbar.draw_all()
264 ax.cbar.draw_all()
265 ax.cbar.patch.figure.canvas.draw()
265 ax.cbar.patch.figure.canvas.draw()
266
266
267 def onBtnPress(self, event):
267 def onBtnPress(self, event):
268 '''
268 '''
269 Event for mouse button press
269 Event for mouse button press
270 '''
270 '''
271 cb_ax = event.inaxes
271 cb_ax = event.inaxes
272 if cb_ax is None:
272 if cb_ax is None:
273 return
273 return
274
274
275 if cb_ax in [ax.cbar.ax for ax in self.axes if ax.cbar]:
275 if cb_ax in [ax.cbar.ax for ax in self.axes if ax.cbar]:
276 cb_ax.press = event.x, event.y
276 cb_ax.press = event.x, event.y
277 else:
277 else:
278 cb_ax.press = None
278 cb_ax.press = None
279
279
280 def onMotion(self, event):
280 def onMotion(self, event):
281 '''
281 '''
282 Event for move inside colorbar
282 Event for move inside colorbar
283 '''
283 '''
284 cb_ax = event.inaxes
284 cb_ax = event.inaxes
285 if cb_ax is None:
285 if cb_ax is None:
286 return
286 return
287 if cb_ax not in [ax.cbar.ax for ax in self.axes if ax.cbar]:
287 if cb_ax not in [ax.cbar.ax for ax in self.axes if ax.cbar]:
288 return
288 return
289 if cb_ax.press is None:
289 if cb_ax.press is None:
290 return
290 return
291
291
292 ax = [ax for ax in self.axes if cb_ax == ax.cbar.ax][0]
292 ax = [ax for ax in self.axes if cb_ax == ax.cbar.ax][0]
293 xprev, yprev = cb_ax.press
293 xprev, yprev = cb_ax.press
294 dx = event.x - xprev
294 dx = event.x - xprev
295 dy = event.y - yprev
295 dy = event.y - yprev
296 cb_ax.press = event.x, event.y
296 cb_ax.press = event.x, event.y
297 scale = ax.cbar.norm.vmax - ax.cbar.norm.vmin
297 scale = ax.cbar.norm.vmax - ax.cbar.norm.vmin
298 perc = 0.03
298 perc = 0.03
299
299
300 if event.button == 1:
300 if event.button == 1:
301 ax.cbar.norm.vmin -= (perc * scale) * numpy.sign(dy)
301 ax.cbar.norm.vmin -= (perc * scale) * numpy.sign(dy)
302 ax.cbar.norm.vmax -= (perc * scale) * numpy.sign(dy)
302 ax.cbar.norm.vmax -= (perc * scale) * numpy.sign(dy)
303 elif event.button == 3:
303 elif event.button == 3:
304 ax.cbar.norm.vmin -= (perc * scale) * numpy.sign(dy)
304 ax.cbar.norm.vmin -= (perc * scale) * numpy.sign(dy)
305 ax.cbar.norm.vmax += (perc * scale) * numpy.sign(dy)
305 ax.cbar.norm.vmax += (perc * scale) * numpy.sign(dy)
306
306
307 ax.cbar.draw_all()
307 ax.cbar.draw_all()
308 ax.plt.set_norm(ax.cbar.norm)
308 ax.plt.set_norm(ax.cbar.norm)
309 ax.cbar.patch.figure.canvas.draw()
309 ax.cbar.patch.figure.canvas.draw()
310
310
311 def onBtnRelease(self, event):
311 def onBtnRelease(self, event):
312 '''
312 '''
313 Event for mouse button release
313 Event for mouse button release
314 '''
314 '''
315 cb_ax = event.inaxes
315 cb_ax = event.inaxes
316 if cb_ax is not None:
316 if cb_ax is not None:
317 cb_ax.press = None
317 cb_ax.press = None
318
318
319 def __add_axes(self, ax, size='30%', pad='8%'):
319 def __add_axes(self, ax, size='30%', pad='8%'):
320 '''
320 '''
321 Add new axes to the given figure
321 Add new axes to the given figure
322 '''
322 '''
323 divider = make_axes_locatable(ax)
323 divider = make_axes_locatable(ax)
324 nax = divider.new_horizontal(size=size, pad=pad)
324 nax = divider.new_horizontal(size=size, pad=pad)
325 ax.figure.add_axes(nax)
325 ax.figure.add_axes(nax)
326 return nax
326 return nax
327
327
328 self.setup()
328 self.setup()
329
329
330 def setup(self):
330 def setup(self):
331 '''
331 '''
332 This method should be implemented in the child class, the following
332 This method should be implemented in the child class, the following
333 attributes should be set:
333 attributes should be set:
334
334
335 self.nrows: number of rows
335 self.nrows: number of rows
336 self.ncols: number of cols
336 self.ncols: number of cols
337 self.nplots: number of plots (channels or pairs)
337 self.nplots: number of plots (channels or pairs)
338 self.ylabel: label for Y axes
338 self.ylabel: label for Y axes
339 self.titles: list of axes title
339 self.titles: list of axes title
340
340
341 '''
341 '''
342 raise(NotImplementedError, 'Implement this method in child class')
342 raise NotImplementedError
343
343
344 def fill_gaps(self, x_buffer, y_buffer, z_buffer):
344 def fill_gaps(self, x_buffer, y_buffer, z_buffer):
345 '''
345 '''
346 Create a masked array for missing data
346 Create a masked array for missing data
347 '''
347 '''
348 if x_buffer.shape[0] < 2:
348 if x_buffer.shape[0] < 2:
349 return x_buffer, y_buffer, z_buffer
349 return x_buffer, y_buffer, z_buffer
350
350
351 deltas = x_buffer[1:] - x_buffer[0:-1]
351 deltas = x_buffer[1:] - x_buffer[0:-1]
352 x_median = numpy.median(deltas)
352 x_median = numpy.median(deltas)
353
353
354 index = numpy.where(deltas > 5 * x_median)
354 index = numpy.where(deltas > 5 * x_median)
355
355
356 if len(index[0]) != 0:
356 if len(index[0]) != 0:
357 z_buffer[::, index[0], ::] = self.__missing
357 z_buffer[::, index[0], ::] = self.__missing
358 z_buffer = numpy.ma.masked_inside(z_buffer,
358 z_buffer = numpy.ma.masked_inside(z_buffer,
359 0.99 * self.__missing,
359 0.99 * self.__missing,
360 1.01 * self.__missing)
360 1.01 * self.__missing)
361
361
362 return x_buffer, y_buffer, z_buffer
362 return x_buffer, y_buffer, z_buffer
363
363
364 def decimate(self):
364 def decimate(self):
365
365
366 # dx = int(len(self.x)/self.__MAXNUMX) + 1
366 # dx = int(len(self.x)/self.__MAXNUMX) + 1
367 dy = int(len(self.y) / self.decimation) + 1
367 dy = int(len(self.y) / self.decimation) + 1
368
368
369 # x = self.x[::dx]
369 # x = self.x[::dx]
370 x = self.x
370 x = self.x
371 y = self.y[::dy]
371 y = self.y[::dy]
372 z = self.z[::, ::, ::dy]
372 z = self.z[::, ::, ::dy]
373
373
374 return x, y, z
374 return x, y, z
375
375
376 def format(self):
376 def format(self):
377 '''
377 '''
378 Set min and max values, labels, ticks and titles
378 Set min and max values, labels, ticks and titles
379 '''
379 '''
380
380
381 if self.xmin is None:
381 if self.xmin is None:
382 xmin = self.min_time
382 xmin = self.min_time
383 else:
383 else:
384 if self.xaxis is 'time':
384 if self.xaxis is 'time':
385 dt = self.getDateTime(self.min_time)
385 dt = self.getDateTime(self.min_time)
386 xmin = (dt.replace(hour=int(self.xmin), minute=0, second=0) -
386 xmin = (dt.replace(hour=int(self.xmin), minute=0, second=0) -
387 datetime.datetime(1970, 1, 1)).total_seconds()
387 datetime.datetime(1970, 1, 1)).total_seconds()
388 if self.data.localtime:
388 if self.data.localtime:
389 xmin += time.timezone
389 xmin += time.timezone
390 else:
390 else:
391 xmin = self.xmin
391 xmin = self.xmin
392
392
393 if self.xmax is None:
393 if self.xmax is None:
394 xmax = xmin + self.xrange * 60 * 60
394 xmax = xmin + self.xrange * 60 * 60
395 else:
395 else:
396 if self.xaxis is 'time':
396 if self.xaxis is 'time':
397 dt = self.getDateTime(self.max_time)
397 dt = self.getDateTime(self.max_time)
398 xmax = (dt.replace(hour=int(self.xmax), minute=59, second=59) -
398 xmax = (dt.replace(hour=int(self.xmax), minute=59, second=59) -
399 datetime.datetime(1970, 1, 1) + datetime.timedelta(seconds=1)).total_seconds()
399 datetime.datetime(1970, 1, 1) + datetime.timedelta(seconds=1)).total_seconds()
400 if self.data.localtime:
400 if self.data.localtime:
401 xmax += time.timezone
401 xmax += time.timezone
402 else:
402 else:
403 xmax = self.xmax
403 xmax = self.xmax
404
404
405 ymin = self.ymin if self.ymin else numpy.nanmin(self.y)
405 ymin = self.ymin if self.ymin else numpy.nanmin(self.y)
406 ymax = self.ymax if self.ymax else numpy.nanmax(self.y)
406 ymax = self.ymax if self.ymax else numpy.nanmax(self.y)
407
407
408 Y = numpy.array([1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000])
408 Y = numpy.array([1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000])
409 i = 1 if numpy.where(abs(ymax-ymin) <= Y)[0][0] < 0 else numpy.where(abs(ymax-ymin) <= Y)[0][0]
409 i = 1 if numpy.where(abs(ymax-ymin) <= Y)[0][0] < 0 else numpy.where(abs(ymax-ymin) <= Y)[0][0]
410 ystep = Y[i] / 10.
410 ystep = Y[i] / 10.
411
411
412 for n, ax in enumerate(self.axes):
412 for n, ax in enumerate(self.axes):
413 if ax.firsttime:
413 if ax.firsttime:
414 ax.set_facecolor(self.bgcolor)
414 ax.set_facecolor(self.bgcolor)
415 ax.yaxis.set_major_locator(MultipleLocator(ystep))
415 ax.yaxis.set_major_locator(MultipleLocator(ystep))
416 ax.xaxis.set_major_locator(MultipleLocator(ystep))
416 ax.xaxis.set_major_locator(MultipleLocator(ystep))
417 if self.xscale:
417 if self.xscale:
418 ax.xaxis.set_major_formatter(FuncFormatter(lambda x, pos: '{0:g}'.format(x*self.xscale)))
418 ax.xaxis.set_major_formatter(FuncFormatter(lambda x, pos: '{0:g}'.format(x*self.xscale)))
419 if self.xscale:
419 if self.xscale:
420 ax.yaxis.set_major_formatter(FuncFormatter(lambda x, pos: '{0:g}'.format(x*self.yscale)))
420 ax.yaxis.set_major_formatter(FuncFormatter(lambda x, pos: '{0:g}'.format(x*self.yscale)))
421 if self.xaxis is 'time':
421 if self.xaxis is 'time':
422 ax.xaxis.set_major_formatter(FuncFormatter(self.__fmtTime))
422 ax.xaxis.set_major_formatter(FuncFormatter(self.__fmtTime))
423 ax.xaxis.set_major_locator(LinearLocator(9))
423 ax.xaxis.set_major_locator(LinearLocator(9))
424 if self.xlabel is not None:
424 if self.xlabel is not None:
425 ax.set_xlabel(self.xlabel)
425 ax.set_xlabel(self.xlabel)
426 ax.set_ylabel(self.ylabel)
426 ax.set_ylabel(self.ylabel)
427 ax.firsttime = False
427 ax.firsttime = False
428 if self.showprofile:
428 if self.showprofile:
429 self.pf_axes[n].set_ylim(ymin, ymax)
429 self.pf_axes[n].set_ylim(ymin, ymax)
430 self.pf_axes[n].set_xlim(self.zmin, self.zmax)
430 self.pf_axes[n].set_xlim(self.zmin, self.zmax)
431 self.pf_axes[n].set_xlabel('dB')
431 self.pf_axes[n].set_xlabel('dB')
432 self.pf_axes[n].grid(b=True, axis='x')
432 self.pf_axes[n].grid(b=True, axis='x')
433 [tick.set_visible(False)
433 [tick.set_visible(False)
434 for tick in self.pf_axes[n].get_yticklabels()]
434 for tick in self.pf_axes[n].get_yticklabels()]
435 if self.colorbar:
435 if self.colorbar:
436 ax.cbar = plt.colorbar(
436 ax.cbar = plt.colorbar(
437 ax.plt, ax=ax, fraction=0.05, pad=0.02, aspect=10)
437 ax.plt, ax=ax, fraction=0.05, pad=0.02, aspect=10)
438 ax.cbar.ax.tick_params(labelsize=8)
438 ax.cbar.ax.tick_params(labelsize=8)
439 ax.cbar.ax.press = None
439 ax.cbar.ax.press = None
440 if self.cb_label:
440 if self.cb_label:
441 ax.cbar.set_label(self.cb_label, size=8)
441 ax.cbar.set_label(self.cb_label, size=8)
442 elif self.cb_labels:
442 elif self.cb_labels:
443 ax.cbar.set_label(self.cb_labels[n], size=8)
443 ax.cbar.set_label(self.cb_labels[n], size=8)
444 else:
444 else:
445 ax.cbar = None
445 ax.cbar = None
446 if self.grid:
446 if self.grid:
447 ax.grid(True)
447 ax.grid(True)
448
448
449 if not self.polar:
449 if not self.polar:
450 ax.set_xlim(xmin, xmax)
450 ax.set_xlim(xmin, xmax)
451 ax.set_ylim(ymin, ymax)
451 ax.set_ylim(ymin, ymax)
452 ax.set_title('{} {} {}'.format(
452 ax.set_title('{} {} {}'.format(
453 self.titles[n],
453 self.titles[n],
454 self.getDateTime(self.max_time).strftime('%Y-%m-%dT%H:%M:%S'),
454 self.getDateTime(self.max_time).strftime('%Y-%m-%dT%H:%M:%S'),
455 self.time_label),
455 self.time_label),
456 size=8)
456 size=8)
457 else:
457 else:
458 ax.set_title('{}'.format(self.titles[n]), size=8)
458 ax.set_title('{}'.format(self.titles[n]), size=8)
459 ax.set_ylim(0, 90)
459 ax.set_ylim(0, 90)
460 ax.set_yticks(numpy.arange(0, 90, 20))
460 ax.set_yticks(numpy.arange(0, 90, 20))
461 ax.yaxis.labelpad = 40
461 ax.yaxis.labelpad = 40
462
462
463 def __plot(self):
463 def __plot(self):
464 '''
464 '''
465 '''
465 '''
466 log.log('Plotting', self.name)
466 log.log('Plotting', self.name)
467
467
468 try:
468 try:
469 self.plot()
469 self.plot()
470 self.format()
470 self.format()
471 except Exception as e:
471 except Exception as e:
472 log.warning('{} Plot could not be updated... check data'.format(self.CODE), self.name)
472 log.warning('{} Plot could not be updated... check data'.format(self.CODE), self.name)
473 log.error(str(e), '')
473 log.error(str(e), '')
474 return
474 return
475
475
476 for n, fig in enumerate(self.figures):
476 for n, fig in enumerate(self.figures):
477 if self.nrows == 0 or self.nplots == 0:
477 if self.nrows == 0 or self.nplots == 0:
478 log.warning('No data', self.name)
478 log.warning('No data', self.name)
479 fig.text(0.5, 0.5, 'No Data', fontsize='large', ha='center')
479 fig.text(0.5, 0.5, 'No Data', fontsize='large', ha='center')
480 fig.canvas.manager.set_window_title(self.CODE)
480 fig.canvas.manager.set_window_title(self.CODE)
481 continue
481 continue
482
482
483 fig.tight_layout()
483 fig.tight_layout()
484 fig.canvas.manager.set_window_title('{} - {}'.format(self.title,
484 fig.canvas.manager.set_window_title('{} - {}'.format(self.title,
485 self.getDateTime(self.max_time).strftime('%Y/%m/%d')))
485 self.getDateTime(self.max_time).strftime('%Y/%m/%d')))
486 fig.canvas.draw()
486 fig.canvas.draw()
487
487
488 if self.save and (self.data.ended or not self.data.buffering):
488 if self.save and (self.data.ended or not self.data.buffering):
489
489
490 if self.save_labels:
490 if self.save_labels:
491 labels = self.save_labels
491 labels = self.save_labels
492 else:
492 else:
493 labels = range(self.nrows)
493 labels = list(range(self.nrows))
494
494
495 if self.oneFigure:
495 if self.oneFigure:
496 label = ''
496 label = ''
497 else:
497 else:
498 label = '-{}'.format(labels[n])
498 label = '-{}'.format(labels[n])
499 figname = os.path.join(
499 figname = os.path.join(
500 self.save,
500 self.save,
501 self.CODE,
501 self.CODE,
502 '{}{}_{}.png'.format(
502 '{}{}_{}.png'.format(
503 self.CODE,
503 self.CODE,
504 label,
504 label,
505 self.getDateTime(self.saveTime).strftime(
505 self.getDateTime(self.saveTime).strftime(
506 '%Y%m%d_%H%M%S'),
506 '%Y%m%d_%H%M%S'),
507 )
507 )
508 )
508 )
509 log.log('Saving figure: {}'.format(figname), self.name)
509 log.log('Saving figure: {}'.format(figname), self.name)
510 if not os.path.isdir(os.path.dirname(figname)):
510 if not os.path.isdir(os.path.dirname(figname)):
511 os.makedirs(os.path.dirname(figname))
511 os.makedirs(os.path.dirname(figname))
512 fig.savefig(figname)
512 fig.savefig(figname)
513
513
514 def plot(self):
514 def plot(self):
515 '''
515 '''
516 '''
516 '''
517 raise(NotImplementedError, 'Implement this method in child class')
517 raise NotImplementedError
518
518
519 def run(self):
519 def run(self):
520
520
521 log.log('Starting', self.name)
521 log.log('Starting', self.name)
522
522
523 context = zmq.Context()
523 context = zmq.Context()
524 receiver = context.socket(zmq.SUB)
524 receiver = context.socket(zmq.SUB)
525 receiver.setsockopt(zmq.SUBSCRIBE, '')
525 receiver.setsockopt(zmq.SUBSCRIBE, '')
526 receiver.setsockopt(zmq.CONFLATE, self.CONFLATE)
526 receiver.setsockopt(zmq.CONFLATE, self.CONFLATE)
527
527
528 if 'server' in self.kwargs['parent']:
528 if 'server' in self.kwargs['parent']:
529 receiver.connect(
529 receiver.connect(
530 'ipc:///tmp/{}.plots'.format(self.kwargs['parent']['server']))
530 'ipc:///tmp/{}.plots'.format(self.kwargs['parent']['server']))
531 else:
531 else:
532 receiver.connect("ipc:///tmp/zmq.plots")
532 receiver.connect("ipc:///tmp/zmq.plots")
533
533
534 while True:
534 while True:
535 try:
535 try:
536 self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK)
536 self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK)
537 if self.data.localtime and self.localtime:
537 if self.data.localtime and self.localtime:
538 self.times = self.data.times
538 self.times = self.data.times
539 elif self.data.localtime and not self.localtime:
539 elif self.data.localtime and not self.localtime:
540 self.times = self.data.times + time.timezone
540 self.times = self.data.times + time.timezone
541 elif not self.data.localtime and self.localtime:
541 elif not self.data.localtime and self.localtime:
542 self.times = self.data.times - time.timezone
542 self.times = self.data.times - time.timezone
543 else:
543 else:
544 self.times = self.data.times
544 self.times = self.data.times
545
545
546 self.min_time = self.times[0]
546 self.min_time = self.times[0]
547 self.max_time = self.times[-1]
547 self.max_time = self.times[-1]
548
548
549 if self.isConfig is False:
549 if self.isConfig is False:
550 self.__setup()
550 self.__setup()
551 self.isConfig = True
551 self.isConfig = True
552
552
553 self.__plot()
553 self.__plot()
554
554
555 except zmq.Again as e:
555 except zmq.Again as e:
556 if self.data and self.data.ended:
556 if self.data and self.data.ended:
557 break
557 break
558 log.log('Waiting for data...')
558 log.log('Waiting for data...')
559 if self.data:
559 if self.data:
560 figpause(self.data.throttle)
560 figpause(self.data.throttle)
561 else:
561 else:
562 time.sleep(2)
562 time.sleep(2)
563
563
564 def close(self):
564 def close(self):
565 if self.data:
565 if self.data:
566 self.__plot()
566 self.__plot()
567
567
568
568
569 class PlotSpectraData(PlotData):
569 class PlotSpectraData(PlotData):
570 '''
570 '''
571 Plot for Spectra data
571 Plot for Spectra data
572 '''
572 '''
573
573
574 CODE = 'spc'
574 CODE = 'spc'
575 colormap = 'jro'
575 colormap = 'jro'
576
576
577 def setup(self):
577 def setup(self):
578 self.nplots = len(self.data.channels)
578 self.nplots = len(self.data.channels)
579 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
579 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
580 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
580 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
581 self.width = 3.4 * self.ncols
581 self.width = 3.4 * self.ncols
582 self.height = 3 * self.nrows
582 self.height = 3 * self.nrows
583 self.cb_label = 'dB'
583 self.cb_label = 'dB'
584 if self.showprofile:
584 if self.showprofile:
585 self.width += 0.8 * self.ncols
585 self.width += 0.8 * self.ncols
586
586
587 self.ylabel = 'Range [km]'
587 self.ylabel = 'Range [km]'
588
588
589 def plot(self):
589 def plot(self):
590 if self.xaxis == "frequency":
590 if self.xaxis == "frequency":
591 x = self.data.xrange[0]
591 x = self.data.xrange[0]
592 self.xlabel = "Frequency (kHz)"
592 self.xlabel = "Frequency (kHz)"
593 elif self.xaxis == "time":
593 elif self.xaxis == "time":
594 x = self.data.xrange[1]
594 x = self.data.xrange[1]
595 self.xlabel = "Time (ms)"
595 self.xlabel = "Time (ms)"
596 else:
596 else:
597 x = self.data.xrange[2]
597 x = self.data.xrange[2]
598 self.xlabel = "Velocity (m/s)"
598 self.xlabel = "Velocity (m/s)"
599
599
600 if self.CODE == 'spc_mean':
600 if self.CODE == 'spc_mean':
601 x = self.data.xrange[2]
601 x = self.data.xrange[2]
602 self.xlabel = "Velocity (m/s)"
602 self.xlabel = "Velocity (m/s)"
603
603
604 self.titles = []
604 self.titles = []
605
605
606 y = self.data.heights
606 y = self.data.heights
607 self.y = y
607 self.y = y
608 z = self.data['spc']
608 z = self.data['spc']
609
609
610 for n, ax in enumerate(self.axes):
610 for n, ax in enumerate(self.axes):
611 noise = self.data['noise'][n][-1]
611 noise = self.data['noise'][n][-1]
612 if self.CODE == 'spc_mean':
612 if self.CODE == 'spc_mean':
613 mean = self.data['mean'][n][-1]
613 mean = self.data['mean'][n][-1]
614 if ax.firsttime:
614 if ax.firsttime:
615 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
615 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
616 self.xmin = self.xmin if self.xmin else -self.xmax
616 self.xmin = self.xmin if self.xmin else -self.xmax
617 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
617 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
618 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
618 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
619 ax.plt = ax.pcolormesh(x, y, z[n].T,
619 ax.plt = ax.pcolormesh(x, y, z[n].T,
620 vmin=self.zmin,
620 vmin=self.zmin,
621 vmax=self.zmax,
621 vmax=self.zmax,
622 cmap=plt.get_cmap(self.colormap)
622 cmap=plt.get_cmap(self.colormap)
623 )
623 )
624
624
625 if self.showprofile:
625 if self.showprofile:
626 ax.plt_profile = self.pf_axes[n].plot(
626 ax.plt_profile = self.pf_axes[n].plot(
627 self.data['rti'][n][-1], y)[0]
627 self.data['rti'][n][-1], y)[0]
628 ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y,
628 ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y,
629 color="k", linestyle="dashed", lw=1)[0]
629 color="k", linestyle="dashed", lw=1)[0]
630 if self.CODE == 'spc_mean':
630 if self.CODE == 'spc_mean':
631 ax.plt_mean = ax.plot(mean, y, color='k')[0]
631 ax.plt_mean = ax.plot(mean, y, color='k')[0]
632 else:
632 else:
633 ax.plt.set_array(z[n].T.ravel())
633 ax.plt.set_array(z[n].T.ravel())
634 if self.showprofile:
634 if self.showprofile:
635 ax.plt_profile.set_data(self.data['rti'][n][-1], y)
635 ax.plt_profile.set_data(self.data['rti'][n][-1], y)
636 ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y)
636 ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y)
637 if self.CODE == 'spc_mean':
637 if self.CODE == 'spc_mean':
638 ax.plt_mean.set_data(mean, y)
638 ax.plt_mean.set_data(mean, y)
639
639
640 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
640 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
641 self.saveTime = self.max_time
641 self.saveTime = self.max_time
642
642
643
643
644 class PlotCrossSpectraData(PlotData):
644 class PlotCrossSpectraData(PlotData):
645
645
646 CODE = 'cspc'
646 CODE = 'cspc'
647 zmin_coh = None
647 zmin_coh = None
648 zmax_coh = None
648 zmax_coh = None
649 zmin_phase = None
649 zmin_phase = None
650 zmax_phase = None
650 zmax_phase = None
651
651
652 def setup(self):
652 def setup(self):
653
653
654 self.ncols = 4
654 self.ncols = 4
655 self.nrows = len(self.data.pairs)
655 self.nrows = len(self.data.pairs)
656 self.nplots = self.nrows * 4
656 self.nplots = self.nrows * 4
657 self.width = 3.4 * self.ncols
657 self.width = 3.4 * self.ncols
658 self.height = 3 * self.nrows
658 self.height = 3 * self.nrows
659 self.ylabel = 'Range [km]'
659 self.ylabel = 'Range [km]'
660 self.showprofile = False
660 self.showprofile = False
661
661
662 def plot(self):
662 def plot(self):
663
663
664 if self.xaxis == "frequency":
664 if self.xaxis == "frequency":
665 x = self.data.xrange[0]
665 x = self.data.xrange[0]
666 self.xlabel = "Frequency (kHz)"
666 self.xlabel = "Frequency (kHz)"
667 elif self.xaxis == "time":
667 elif self.xaxis == "time":
668 x = self.data.xrange[1]
668 x = self.data.xrange[1]
669 self.xlabel = "Time (ms)"
669 self.xlabel = "Time (ms)"
670 else:
670 else:
671 x = self.data.xrange[2]
671 x = self.data.xrange[2]
672 self.xlabel = "Velocity (m/s)"
672 self.xlabel = "Velocity (m/s)"
673
673
674 self.titles = []
674 self.titles = []
675
675
676 y = self.data.heights
676 y = self.data.heights
677 self.y = y
677 self.y = y
678 spc = self.data['spc']
678 spc = self.data['spc']
679 cspc = self.data['cspc']
679 cspc = self.data['cspc']
680
680
681 for n in range(self.nrows):
681 for n in range(self.nrows):
682 noise = self.data['noise'][n][-1]
682 noise = self.data['noise'][n][-1]
683 pair = self.data.pairs[n]
683 pair = self.data.pairs[n]
684 ax = self.axes[4 * n]
684 ax = self.axes[4 * n]
685 ax3 = self.axes[4 * n + 3]
685 ax3 = self.axes[4 * n + 3]
686 if ax.firsttime:
686 if ax.firsttime:
687 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
687 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
688 self.xmin = self.xmin if self.xmin else -self.xmax
688 self.xmin = self.xmin if self.xmin else -self.xmax
689 self.zmin = self.zmin if self.zmin else numpy.nanmin(spc)
689 self.zmin = self.zmin if self.zmin else numpy.nanmin(spc)
690 self.zmax = self.zmax if self.zmax else numpy.nanmax(spc)
690 self.zmax = self.zmax if self.zmax else numpy.nanmax(spc)
691 ax.plt = ax.pcolormesh(x, y, spc[pair[0]].T,
691 ax.plt = ax.pcolormesh(x, y, spc[pair[0]].T,
692 vmin=self.zmin,
692 vmin=self.zmin,
693 vmax=self.zmax,
693 vmax=self.zmax,
694 cmap=plt.get_cmap(self.colormap)
694 cmap=plt.get_cmap(self.colormap)
695 )
695 )
696 else:
696 else:
697 ax.plt.set_array(spc[pair[0]].T.ravel())
697 ax.plt.set_array(spc[pair[0]].T.ravel())
698 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
698 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
699
699
700 ax = self.axes[4 * n + 1]
700 ax = self.axes[4 * n + 1]
701 if ax.firsttime:
701 if ax.firsttime:
702 ax.plt = ax.pcolormesh(x, y, spc[pair[1]].T,
702 ax.plt = ax.pcolormesh(x, y, spc[pair[1]].T,
703 vmin=self.zmin,
703 vmin=self.zmin,
704 vmax=self.zmax,
704 vmax=self.zmax,
705 cmap=plt.get_cmap(self.colormap)
705 cmap=plt.get_cmap(self.colormap)
706 )
706 )
707 else:
707 else:
708 ax.plt.set_array(spc[pair[1]].T.ravel())
708 ax.plt.set_array(spc[pair[1]].T.ravel())
709 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
709 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
710
710
711 out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
711 out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
712 coh = numpy.abs(out)
712 coh = numpy.abs(out)
713 phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
713 phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
714
714
715 ax = self.axes[4 * n + 2]
715 ax = self.axes[4 * n + 2]
716 if ax.firsttime:
716 if ax.firsttime:
717 ax.plt = ax.pcolormesh(x, y, coh.T,
717 ax.plt = ax.pcolormesh(x, y, coh.T,
718 vmin=0,
718 vmin=0,
719 vmax=1,
719 vmax=1,
720 cmap=plt.get_cmap(self.colormap_coh)
720 cmap=plt.get_cmap(self.colormap_coh)
721 )
721 )
722 else:
722 else:
723 ax.plt.set_array(coh.T.ravel())
723 ax.plt.set_array(coh.T.ravel())
724 self.titles.append(
724 self.titles.append(
725 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1]))
725 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1]))
726
726
727 ax = self.axes[4 * n + 3]
727 ax = self.axes[4 * n + 3]
728 if ax.firsttime:
728 if ax.firsttime:
729 ax.plt = ax.pcolormesh(x, y, phase.T,
729 ax.plt = ax.pcolormesh(x, y, phase.T,
730 vmin=-180,
730 vmin=-180,
731 vmax=180,
731 vmax=180,
732 cmap=plt.get_cmap(self.colormap_phase)
732 cmap=plt.get_cmap(self.colormap_phase)
733 )
733 )
734 else:
734 else:
735 ax.plt.set_array(phase.T.ravel())
735 ax.plt.set_array(phase.T.ravel())
736 self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1]))
736 self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1]))
737
737
738 self.saveTime = self.max_time
738 self.saveTime = self.max_time
739
739
740
740
741 class PlotSpectraMeanData(PlotSpectraData):
741 class PlotSpectraMeanData(PlotSpectraData):
742 '''
742 '''
743 Plot for Spectra and Mean
743 Plot for Spectra and Mean
744 '''
744 '''
745 CODE = 'spc_mean'
745 CODE = 'spc_mean'
746 colormap = 'jro'
746 colormap = 'jro'
747
747
748
748
749 class PlotRTIData(PlotData):
749 class PlotRTIData(PlotData):
750 '''
750 '''
751 Plot for RTI data
751 Plot for RTI data
752 '''
752 '''
753
753
754 CODE = 'rti'
754 CODE = 'rti'
755 colormap = 'jro'
755 colormap = 'jro'
756
756
757 def setup(self):
757 def setup(self):
758 self.xaxis = 'time'
758 self.xaxis = 'time'
759 self.ncols = 1
759 self.ncols = 1
760 self.nrows = len(self.data.channels)
760 self.nrows = len(self.data.channels)
761 self.nplots = len(self.data.channels)
761 self.nplots = len(self.data.channels)
762 self.ylabel = 'Range [km]'
762 self.ylabel = 'Range [km]'
763 self.cb_label = 'dB'
763 self.cb_label = 'dB'
764 self.titles = ['{} Channel {}'.format(
764 self.titles = ['{} Channel {}'.format(
765 self.CODE.upper(), x) for x in range(self.nrows)]
765 self.CODE.upper(), x) for x in range(self.nrows)]
766
766
767 def plot(self):
767 def plot(self):
768 self.x = self.times
768 self.x = self.times
769 self.y = self.data.heights
769 self.y = self.data.heights
770 self.z = self.data[self.CODE]
770 self.z = self.data[self.CODE]
771 self.z = numpy.ma.masked_invalid(self.z)
771 self.z = numpy.ma.masked_invalid(self.z)
772
772
773 if self.decimation is None:
773 if self.decimation is None:
774 x, y, z = self.fill_gaps(self.x, self.y, self.z)
774 x, y, z = self.fill_gaps(self.x, self.y, self.z)
775 else:
775 else:
776 x, y, z = self.fill_gaps(*self.decimate())
776 x, y, z = self.fill_gaps(*self.decimate())
777
777
778 for n, ax in enumerate(self.axes):
778 for n, ax in enumerate(self.axes):
779 self.zmin = self.zmin if self.zmin else numpy.min(self.z)
779 self.zmin = self.zmin if self.zmin else numpy.min(self.z)
780 self.zmax = self.zmax if self.zmax else numpy.max(self.z)
780 self.zmax = self.zmax if self.zmax else numpy.max(self.z)
781 if ax.firsttime:
781 if ax.firsttime:
782 ax.plt = ax.pcolormesh(x, y, z[n].T,
782 ax.plt = ax.pcolormesh(x, y, z[n].T,
783 vmin=self.zmin,
783 vmin=self.zmin,
784 vmax=self.zmax,
784 vmax=self.zmax,
785 cmap=plt.get_cmap(self.colormap)
785 cmap=plt.get_cmap(self.colormap)
786 )
786 )
787 if self.showprofile:
787 if self.showprofile:
788 ax.plot_profile = self.pf_axes[n].plot(
788 ax.plot_profile = self.pf_axes[n].plot(
789 self.data['rti'][n][-1], self.y)[0]
789 self.data['rti'][n][-1], self.y)[0]
790 ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y,
790 ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y,
791 color="k", linestyle="dashed", lw=1)[0]
791 color="k", linestyle="dashed", lw=1)[0]
792 else:
792 else:
793 ax.collections.remove(ax.collections[0])
793 ax.collections.remove(ax.collections[0])
794 ax.plt = ax.pcolormesh(x, y, z[n].T,
794 ax.plt = ax.pcolormesh(x, y, z[n].T,
795 vmin=self.zmin,
795 vmin=self.zmin,
796 vmax=self.zmax,
796 vmax=self.zmax,
797 cmap=plt.get_cmap(self.colormap)
797 cmap=plt.get_cmap(self.colormap)
798 )
798 )
799 if self.showprofile:
799 if self.showprofile:
800 ax.plot_profile.set_data(self.data['rti'][n][-1], self.y)
800 ax.plot_profile.set_data(self.data['rti'][n][-1], self.y)
801 ax.plot_noise.set_data(numpy.repeat(
801 ax.plot_noise.set_data(numpy.repeat(
802 self.data['noise'][n][-1], len(self.y)), self.y)
802 self.data['noise'][n][-1], len(self.y)), self.y)
803
803
804 self.saveTime = self.min_time
804 self.saveTime = self.min_time
805
805
806
806
807 class PlotCOHData(PlotRTIData):
807 class PlotCOHData(PlotRTIData):
808 '''
808 '''
809 Plot for Coherence data
809 Plot for Coherence data
810 '''
810 '''
811
811
812 CODE = 'coh'
812 CODE = 'coh'
813
813
814 def setup(self):
814 def setup(self):
815 self.xaxis = 'time'
815 self.xaxis = 'time'
816 self.ncols = 1
816 self.ncols = 1
817 self.nrows = len(self.data.pairs)
817 self.nrows = len(self.data.pairs)
818 self.nplots = len(self.data.pairs)
818 self.nplots = len(self.data.pairs)
819 self.ylabel = 'Range [km]'
819 self.ylabel = 'Range [km]'
820 if self.CODE == 'coh':
820 if self.CODE == 'coh':
821 self.cb_label = ''
821 self.cb_label = ''
822 self.titles = [
822 self.titles = [
823 'Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
823 'Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
824 else:
824 else:
825 self.cb_label = 'Degrees'
825 self.cb_label = 'Degrees'
826 self.titles = [
826 self.titles = [
827 'Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
827 'Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
828
828
829
829
830 class PlotPHASEData(PlotCOHData):
830 class PlotPHASEData(PlotCOHData):
831 '''
831 '''
832 Plot for Phase map data
832 Plot for Phase map data
833 '''
833 '''
834
834
835 CODE = 'phase'
835 CODE = 'phase'
836 colormap = 'seismic'
836 colormap = 'seismic'
837
837
838
838
839 class PlotNoiseData(PlotData):
839 class PlotNoiseData(PlotData):
840 '''
840 '''
841 Plot for noise
841 Plot for noise
842 '''
842 '''
843
843
844 CODE = 'noise'
844 CODE = 'noise'
845
845
846 def setup(self):
846 def setup(self):
847 self.xaxis = 'time'
847 self.xaxis = 'time'
848 self.ncols = 1
848 self.ncols = 1
849 self.nrows = 1
849 self.nrows = 1
850 self.nplots = 1
850 self.nplots = 1
851 self.ylabel = 'Intensity [dB]'
851 self.ylabel = 'Intensity [dB]'
852 self.titles = ['Noise']
852 self.titles = ['Noise']
853 self.colorbar = False
853 self.colorbar = False
854
854
855 def plot(self):
855 def plot(self):
856
856
857 x = self.times
857 x = self.times
858 xmin = self.min_time
858 xmin = self.min_time
859 xmax = xmin + self.xrange * 60 * 60
859 xmax = xmin + self.xrange * 60 * 60
860 Y = self.data[self.CODE]
860 Y = self.data[self.CODE]
861
861
862 if self.axes[0].firsttime:
862 if self.axes[0].firsttime:
863 for ch in self.data.channels:
863 for ch in self.data.channels:
864 y = Y[ch]
864 y = Y[ch]
865 self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch))
865 self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch))
866 plt.legend()
866 plt.legend()
867 else:
867 else:
868 for ch in self.data.channels:
868 for ch in self.data.channels:
869 y = Y[ch]
869 y = Y[ch]
870 self.axes[0].lines[ch].set_data(x, y)
870 self.axes[0].lines[ch].set_data(x, y)
871
871
872 self.ymin = numpy.nanmin(Y) - 5
872 self.ymin = numpy.nanmin(Y) - 5
873 self.ymax = numpy.nanmax(Y) + 5
873 self.ymax = numpy.nanmax(Y) + 5
874 self.saveTime = self.min_time
874 self.saveTime = self.min_time
875
875
876
876
877 class PlotSNRData(PlotRTIData):
877 class PlotSNRData(PlotRTIData):
878 '''
878 '''
879 Plot for SNR Data
879 Plot for SNR Data
880 '''
880 '''
881
881
882 CODE = 'snr'
882 CODE = 'snr'
883 colormap = 'jet'
883 colormap = 'jet'
884
884
885
885
886 class PlotDOPData(PlotRTIData):
886 class PlotDOPData(PlotRTIData):
887 '''
887 '''
888 Plot for DOPPLER Data
888 Plot for DOPPLER Data
889 '''
889 '''
890
890
891 CODE = 'dop'
891 CODE = 'dop'
892 colormap = 'jet'
892 colormap = 'jet'
893
893
894
894
895 class PlotSkyMapData(PlotData):
895 class PlotSkyMapData(PlotData):
896 '''
896 '''
897 Plot for meteors detection data
897 Plot for meteors detection data
898 '''
898 '''
899
899
900 CODE = 'param'
900 CODE = 'param'
901
901
902 def setup(self):
902 def setup(self):
903
903
904 self.ncols = 1
904 self.ncols = 1
905 self.nrows = 1
905 self.nrows = 1
906 self.width = 7.2
906 self.width = 7.2
907 self.height = 7.2
907 self.height = 7.2
908 self.nplots = 1
908 self.nplots = 1
909 self.xlabel = 'Zonal Zenith Angle (deg)'
909 self.xlabel = 'Zonal Zenith Angle (deg)'
910 self.ylabel = 'Meridional Zenith Angle (deg)'
910 self.ylabel = 'Meridional Zenith Angle (deg)'
911 self.polar = True
911 self.polar = True
912 self.ymin = -180
912 self.ymin = -180
913 self.ymax = 180
913 self.ymax = 180
914 self.colorbar = False
914 self.colorbar = False
915
915
916 def plot(self):
916 def plot(self):
917
917
918 arrayParameters = numpy.concatenate(self.data['param'])
918 arrayParameters = numpy.concatenate(self.data['param'])
919 error = arrayParameters[:, -1]
919 error = arrayParameters[:, -1]
920 indValid = numpy.where(error == 0)[0]
920 indValid = numpy.where(error == 0)[0]
921 finalMeteor = arrayParameters[indValid, :]
921 finalMeteor = arrayParameters[indValid, :]
922 finalAzimuth = finalMeteor[:, 3]
922 finalAzimuth = finalMeteor[:, 3]
923 finalZenith = finalMeteor[:, 4]
923 finalZenith = finalMeteor[:, 4]
924
924
925 x = finalAzimuth * numpy.pi / 180
925 x = finalAzimuth * numpy.pi / 180
926 y = finalZenith
926 y = finalZenith
927
927
928 ax = self.axes[0]
928 ax = self.axes[0]
929
929
930 if ax.firsttime:
930 if ax.firsttime:
931 ax.plot = ax.plot(x, y, 'bo', markersize=5)[0]
931 ax.plot = ax.plot(x, y, 'bo', markersize=5)[0]
932 else:
932 else:
933 ax.plot.set_data(x, y)
933 ax.plot.set_data(x, y)
934
934
935 dt1 = self.getDateTime(self.min_time).strftime('%y/%m/%d %H:%M:%S')
935 dt1 = self.getDateTime(self.min_time).strftime('%y/%m/%d %H:%M:%S')
936 dt2 = self.getDateTime(self.max_time).strftime('%y/%m/%d %H:%M:%S')
936 dt2 = self.getDateTime(self.max_time).strftime('%y/%m/%d %H:%M:%S')
937 title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1,
937 title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1,
938 dt2,
938 dt2,
939 len(x))
939 len(x))
940 self.titles[0] = title
940 self.titles[0] = title
941 self.saveTime = self.max_time
941 self.saveTime = self.max_time
942
942
943
943
944 class PlotParamData(PlotRTIData):
944 class PlotParamData(PlotRTIData):
945 '''
945 '''
946 Plot for data_param object
946 Plot for data_param object
947 '''
947 '''
948
948
949 CODE = 'param'
949 CODE = 'param'
950 colormap = 'seismic'
950 colormap = 'seismic'
951
951
952 def setup(self):
952 def setup(self):
953 self.xaxis = 'time'
953 self.xaxis = 'time'
954 self.ncols = 1
954 self.ncols = 1
955 self.nrows = self.data.shape(self.CODE)[0]
955 self.nrows = self.data.shape(self.CODE)[0]
956 self.nplots = self.nrows
956 self.nplots = self.nrows
957 if self.showSNR:
957 if self.showSNR:
958 self.nrows += 1
958 self.nrows += 1
959 self.nplots += 1
959 self.nplots += 1
960
960
961 self.ylabel = 'Height [km]'
961 self.ylabel = 'Height [km]'
962 if not self.titles:
962 if not self.titles:
963 self.titles = self.data.parameters \
963 self.titles = self.data.parameters \
964 if self.data.parameters else ['Param {}'.format(x) for x in xrange(self.nrows)]
964 if self.data.parameters else ['Param {}'.format(x) for x in range(self.nrows)]
965 if self.showSNR:
965 if self.showSNR:
966 self.titles.append('SNR')
966 self.titles.append('SNR')
967
967
968 def plot(self):
968 def plot(self):
969 self.data.normalize_heights()
969 self.data.normalize_heights()
970 self.x = self.times
970 self.x = self.times
971 self.y = self.data.heights
971 self.y = self.data.heights
972 if self.showSNR:
972 if self.showSNR:
973 self.z = numpy.concatenate(
973 self.z = numpy.concatenate(
974 (self.data[self.CODE], self.data['snr'])
974 (self.data[self.CODE], self.data['snr'])
975 )
975 )
976 else:
976 else:
977 self.z = self.data[self.CODE]
977 self.z = self.data[self.CODE]
978
978
979 self.z = numpy.ma.masked_invalid(self.z)
979 self.z = numpy.ma.masked_invalid(self.z)
980
980
981 if self.decimation is None:
981 if self.decimation is None:
982 x, y, z = self.fill_gaps(self.x, self.y, self.z)
982 x, y, z = self.fill_gaps(self.x, self.y, self.z)
983 else:
983 else:
984 x, y, z = self.fill_gaps(*self.decimate())
984 x, y, z = self.fill_gaps(*self.decimate())
985
985
986 for n, ax in enumerate(self.axes):
986 for n, ax in enumerate(self.axes):
987
987
988 self.zmax = self.zmax if self.zmax is not None else numpy.max(
988 self.zmax = self.zmax if self.zmax is not None else numpy.max(
989 self.z[n])
989 self.z[n])
990 self.zmin = self.zmin if self.zmin is not None else numpy.min(
990 self.zmin = self.zmin if self.zmin is not None else numpy.min(
991 self.z[n])
991 self.z[n])
992
992
993 if ax.firsttime:
993 if ax.firsttime:
994 if self.zlimits is not None:
994 if self.zlimits is not None:
995 self.zmin, self.zmax = self.zlimits[n]
995 self.zmin, self.zmax = self.zlimits[n]
996
996
997 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
997 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
998 vmin=self.zmin,
998 vmin=self.zmin,
999 vmax=self.zmax,
999 vmax=self.zmax,
1000 cmap=self.cmaps[n]
1000 cmap=self.cmaps[n]
1001 )
1001 )
1002 else:
1002 else:
1003 if self.zlimits is not None:
1003 if self.zlimits is not None:
1004 self.zmin, self.zmax = self.zlimits[n]
1004 self.zmin, self.zmax = self.zlimits[n]
1005 ax.collections.remove(ax.collections[0])
1005 ax.collections.remove(ax.collections[0])
1006 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
1006 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
1007 vmin=self.zmin,
1007 vmin=self.zmin,
1008 vmax=self.zmax,
1008 vmax=self.zmax,
1009 cmap=self.cmaps[n]
1009 cmap=self.cmaps[n]
1010 )
1010 )
1011
1011
1012 self.saveTime = self.min_time
1012 self.saveTime = self.min_time
1013
1013
1014
1014
1015 class PlotOutputData(PlotParamData):
1015 class PlotOutputData(PlotParamData):
1016 '''
1016 '''
1017 Plot data_output object
1017 Plot data_output object
1018 '''
1018 '''
1019
1019
1020 CODE = 'output'
1020 CODE = 'output'
1021 colormap = 'seismic'
1021 colormap = 'seismic'
1022
1022
1023
1023
1024 class PlotPolarMapData(PlotData):
1024 class PlotPolarMapData(PlotData):
1025 '''
1025 '''
1026 Plot for meteors detection data
1026 Plot for meteors detection data
1027 '''
1027 '''
1028
1028
1029 CODE = 'param'
1029 CODE = 'param'
1030 colormap = 'seismic'
1030 colormap = 'seismic'
1031
1031
1032 def setup(self):
1032 def setup(self):
1033 self.ncols = 1
1033 self.ncols = 1
1034 self.nrows = 1
1034 self.nrows = 1
1035 self.width = 9
1035 self.width = 9
1036 self.height = 8
1036 self.height = 8
1037 self.mode = self.data.meta['mode']
1037 self.mode = self.data.meta['mode']
1038 if self.channels is not None:
1038 if self.channels is not None:
1039 self.nplots = len(self.channels)
1039 self.nplots = len(self.channels)
1040 self.nrows = len(self.channels)
1040 self.nrows = len(self.channels)
1041 else:
1041 else:
1042 self.nplots = self.data.shape(self.CODE)[0]
1042 self.nplots = self.data.shape(self.CODE)[0]
1043 self.nrows = self.nplots
1043 self.nrows = self.nplots
1044 self.channels = range(self.nplots)
1044 self.channels = list(range(self.nplots))
1045 if self.mode == 'E':
1045 if self.mode == 'E':
1046 self.xlabel = 'Longitude'
1046 self.xlabel = 'Longitude'
1047 self.ylabel = 'Latitude'
1047 self.ylabel = 'Latitude'
1048 else:
1048 else:
1049 self.xlabel = 'Range (km)'
1049 self.xlabel = 'Range (km)'
1050 self.ylabel = 'Height (km)'
1050 self.ylabel = 'Height (km)'
1051 self.bgcolor = 'white'
1051 self.bgcolor = 'white'
1052 self.cb_labels = self.data.meta['units']
1052 self.cb_labels = self.data.meta['units']
1053 self.lat = self.data.meta['latitude']
1053 self.lat = self.data.meta['latitude']
1054 self.lon = self.data.meta['longitude']
1054 self.lon = self.data.meta['longitude']
1055 self.xmin, self.xmax = float(km2deg(self.xmin) + self.lon), float(km2deg(self.xmax) + self.lon)
1055 self.xmin, self.xmax = float(km2deg(self.xmin) + self.lon), float(km2deg(self.xmax) + self.lon)
1056 self.ymin, self.ymax = float(km2deg(self.ymin) + self.lat), float(km2deg(self.ymax) + self.lat)
1056 self.ymin, self.ymax = float(km2deg(self.ymin) + self.lat), float(km2deg(self.ymax) + self.lat)
1057 # self.polar = True
1057 # self.polar = True
1058
1058
1059 def plot(self):
1059 def plot(self):
1060
1060
1061 for n, ax in enumerate(self.axes):
1061 for n, ax in enumerate(self.axes):
1062 data = self.data['param'][self.channels[n]]
1062 data = self.data['param'][self.channels[n]]
1063
1063
1064 zeniths = numpy.linspace(0, self.data.meta['max_range'], data.shape[1])
1064 zeniths = numpy.linspace(0, self.data.meta['max_range'], data.shape[1])
1065 if self.mode == 'E':
1065 if self.mode == 'E':
1066 azimuths = -numpy.radians(self.data.heights)+numpy.pi/2
1066 azimuths = -numpy.radians(self.data.heights)+numpy.pi/2
1067 r, theta = numpy.meshgrid(zeniths, azimuths)
1067 r, theta = numpy.meshgrid(zeniths, azimuths)
1068 x, y = r*numpy.cos(theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])), r*numpy.sin(theta)*numpy.cos(numpy.radians(self.data.meta['elevation']))
1068 x, y = r*numpy.cos(theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])), r*numpy.sin(theta)*numpy.cos(numpy.radians(self.data.meta['elevation']))
1069 x = km2deg(x) + self.lon
1069 x = km2deg(x) + self.lon
1070 y = km2deg(y) + self.lat
1070 y = km2deg(y) + self.lat
1071 else:
1071 else:
1072 azimuths = numpy.radians(self.data.heights)
1072 azimuths = numpy.radians(self.data.heights)
1073 r, theta = numpy.meshgrid(zeniths, azimuths)
1073 r, theta = numpy.meshgrid(zeniths, azimuths)
1074 x, y = r*numpy.cos(theta), r*numpy.sin(theta)
1074 x, y = r*numpy.cos(theta), r*numpy.sin(theta)
1075 self.y = zeniths
1075 self.y = zeniths
1076
1076
1077 if ax.firsttime:
1077 if ax.firsttime:
1078 if self.zlimits is not None:
1078 if self.zlimits is not None:
1079 self.zmin, self.zmax = self.zlimits[n]
1079 self.zmin, self.zmax = self.zlimits[n]
1080 ax.plt = ax.pcolormesh(#r, theta, numpy.ma.array(data, mask=numpy.isnan(data)),
1080 ax.plt = ax.pcolormesh(#r, theta, numpy.ma.array(data, mask=numpy.isnan(data)),
1081 x, y, numpy.ma.array(data, mask=numpy.isnan(data)),
1081 x, y, numpy.ma.array(data, mask=numpy.isnan(data)),
1082 vmin=self.zmin,
1082 vmin=self.zmin,
1083 vmax=self.zmax,
1083 vmax=self.zmax,
1084 cmap=self.cmaps[n])
1084 cmap=self.cmaps[n])
1085 else:
1085 else:
1086 if self.zlimits is not None:
1086 if self.zlimits is not None:
1087 self.zmin, self.zmax = self.zlimits[n]
1087 self.zmin, self.zmax = self.zlimits[n]
1088 ax.collections.remove(ax.collections[0])
1088 ax.collections.remove(ax.collections[0])
1089 ax.plt = ax.pcolormesh(# r, theta, numpy.ma.array(data, mask=numpy.isnan(data)),
1089 ax.plt = ax.pcolormesh(# r, theta, numpy.ma.array(data, mask=numpy.isnan(data)),
1090 x, y, numpy.ma.array(data, mask=numpy.isnan(data)),
1090 x, y, numpy.ma.array(data, mask=numpy.isnan(data)),
1091 vmin=self.zmin,
1091 vmin=self.zmin,
1092 vmax=self.zmax,
1092 vmax=self.zmax,
1093 cmap=self.cmaps[n])
1093 cmap=self.cmaps[n])
1094
1094
1095 if self.mode == 'A':
1095 if self.mode == 'A':
1096 continue
1096 continue
1097
1097
1098 # plot district names
1098 # plot district names
1099 f = open('/data/workspace/schain_scripts/distrito.csv')
1099 f = open('/data/workspace/schain_scripts/distrito.csv')
1100 for line in f:
1100 for line in f:
1101 label, lon, lat = [s.strip() for s in line.split(',') if s]
1101 label, lon, lat = [s.strip() for s in line.split(',') if s]
1102 lat = float(lat)
1102 lat = float(lat)
1103 lon = float(lon)
1103 lon = float(lon)
1104 # ax.plot(lon, lat, '.b', ms=2)
1104 # ax.plot(lon, lat, '.b', ms=2)
1105 ax.text(lon, lat, label.decode('utf8'), ha='center', va='bottom', size='8', color='black')
1105 ax.text(lon, lat, label.decode('utf8'), ha='center', va='bottom', size='8', color='black')
1106
1106
1107 # plot limites
1107 # plot limites
1108 limites =[]
1108 limites =[]
1109 tmp = []
1109 tmp = []
1110 for line in open('/data/workspace/schain_scripts/lima.csv'):
1110 for line in open('/data/workspace/schain_scripts/lima.csv'):
1111 if '#' in line:
1111 if '#' in line:
1112 if tmp:
1112 if tmp:
1113 limites.append(tmp)
1113 limites.append(tmp)
1114 tmp = []
1114 tmp = []
1115 continue
1115 continue
1116 values = line.strip().split(',')
1116 values = line.strip().split(',')
1117 tmp.append((float(values[0]), float(values[1])))
1117 tmp.append((float(values[0]), float(values[1])))
1118 for points in limites:
1118 for points in limites:
1119 ax.add_patch(Polygon(points, ec='k', fc='none', ls='--', lw=0.5))
1119 ax.add_patch(Polygon(points, ec='k', fc='none', ls='--', lw=0.5))
1120
1120
1121 # plot Cuencas
1121 # plot Cuencas
1122 for cuenca in ('rimac', 'lurin', 'mala', 'chillon', 'chilca', 'chancay-huaral'):
1122 for cuenca in ('rimac', 'lurin', 'mala', 'chillon', 'chilca', 'chancay-huaral'):
1123 f = open('/data/workspace/schain_scripts/{}.csv'.format(cuenca))
1123 f = open('/data/workspace/schain_scripts/{}.csv'.format(cuenca))
1124 values = [line.strip().split(',') for line in f]
1124 values = [line.strip().split(',') for line in f]
1125 points = [(float(s[0]), float(s[1])) for s in values]
1125 points = [(float(s[0]), float(s[1])) for s in values]
1126 ax.add_patch(Polygon(points, ec='b', fc='none'))
1126 ax.add_patch(Polygon(points, ec='b', fc='none'))
1127
1127
1128 # plot grid
1128 # plot grid
1129 for r in (15, 30, 45, 60):
1129 for r in (15, 30, 45, 60):
1130 ax.add_artist(plt.Circle((self.lon, self.lat), km2deg(r), color='0.6', fill=False, lw=0.2))
1130 ax.add_artist(plt.Circle((self.lon, self.lat), km2deg(r), color='0.6', fill=False, lw=0.2))
1131 ax.text(
1131 ax.text(
1132 self.lon + (km2deg(r))*numpy.cos(60*numpy.pi/180),
1132 self.lon + (km2deg(r))*numpy.cos(60*numpy.pi/180),
1133 self.lat + (km2deg(r))*numpy.sin(60*numpy.pi/180),
1133 self.lat + (km2deg(r))*numpy.sin(60*numpy.pi/180),
1134 '{}km'.format(r),
1134 '{}km'.format(r),
1135 ha='center', va='bottom', size='8', color='0.6', weight='heavy')
1135 ha='center', va='bottom', size='8', color='0.6', weight='heavy')
1136
1136
1137 if self.mode == 'E':
1137 if self.mode == 'E':
1138 title = 'El={}$^\circ$'.format(self.data.meta['elevation'])
1138 title = 'El={}$^\circ$'.format(self.data.meta['elevation'])
1139 label = 'E{:02d}'.format(int(self.data.meta['elevation']))
1139 label = 'E{:02d}'.format(int(self.data.meta['elevation']))
1140 else:
1140 else:
1141 title = 'Az={}$^\circ$'.format(self.data.meta['azimuth'])
1141 title = 'Az={}$^\circ$'.format(self.data.meta['azimuth'])
1142 label = 'A{:02d}'.format(int(self.data.meta['azimuth']))
1142 label = 'A{:02d}'.format(int(self.data.meta['azimuth']))
1143
1143
1144 self.save_labels = ['{}-{}'.format(lbl, label) for lbl in self.labels]
1144 self.save_labels = ['{}-{}'.format(lbl, label) for lbl in self.labels]
1145 self.titles = ['{} {}'.format(self.data.parameters[x], title) for x in self.channels]
1145 self.titles = ['{} {}'.format(self.data.parameters[x], title) for x in self.channels]
1146 self.saveTime = self.max_time
1146 self.saveTime = self.max_time
1147
1147
1148
1148 No newline at end of file
@@ -1,329 +1,329
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
10 from .figure import Figure, isRealtime
11 from plotting_codes import *
11 from .plotting_codes import *
12
12
13 class SpectraHeisScope(Figure):
13 class SpectraHeisScope(Figure):
14
14
15
15
16 isConfig = None
16 isConfig = None
17 __nsubplots = None
17 __nsubplots = None
18
18
19 WIDTHPROF = None
19 WIDTHPROF = None
20 HEIGHTPROF = None
20 HEIGHTPROF = None
21 PREFIX = 'spc'
21 PREFIX = 'spc'
22
22
23 def __init__(self, **kwargs):
23 def __init__(self, **kwargs):
24
24
25 Figure.__init__(self, **kwargs)
25 Figure.__init__(self, **kwargs)
26 self.isConfig = False
26 self.isConfig = False
27 self.__nsubplots = 1
27 self.__nsubplots = 1
28
28
29 self.WIDTH = 230
29 self.WIDTH = 230
30 self.HEIGHT = 250
30 self.HEIGHT = 250
31 self.WIDTHPROF = 120
31 self.WIDTHPROF = 120
32 self.HEIGHTPROF = 0
32 self.HEIGHTPROF = 0
33 self.counter_imagwr = 0
33 self.counter_imagwr = 0
34
34
35 self.PLOT_CODE = SPEC_CODE
35 self.PLOT_CODE = SPEC_CODE
36
36
37 def getSubplots(self):
37 def getSubplots(self):
38
38
39 ncol = int(numpy.sqrt(self.nplots)+0.9)
39 ncol = int(numpy.sqrt(self.nplots)+0.9)
40 nrow = int(self.nplots*1./ncol + 0.9)
40 nrow = int(self.nplots*1./ncol + 0.9)
41
41
42 return nrow, ncol
42 return nrow, ncol
43
43
44 def setup(self, id, nplots, wintitle, show):
44 def setup(self, id, nplots, wintitle, show):
45
45
46 showprofile = False
46 showprofile = False
47 self.__showprofile = showprofile
47 self.__showprofile = showprofile
48 self.nplots = nplots
48 self.nplots = nplots
49
49
50 ncolspan = 1
50 ncolspan = 1
51 colspan = 1
51 colspan = 1
52 if showprofile:
52 if showprofile:
53 ncolspan = 3
53 ncolspan = 3
54 colspan = 2
54 colspan = 2
55 self.__nsubplots = 2
55 self.__nsubplots = 2
56
56
57 self.createFigure(id = id,
57 self.createFigure(id = id,
58 wintitle = wintitle,
58 wintitle = wintitle,
59 widthplot = self.WIDTH + self.WIDTHPROF,
59 widthplot = self.WIDTH + self.WIDTHPROF,
60 heightplot = self.HEIGHT + self.HEIGHTPROF,
60 heightplot = self.HEIGHT + self.HEIGHTPROF,
61 show = show)
61 show = show)
62
62
63 nrow, ncol = self.getSubplots()
63 nrow, ncol = self.getSubplots()
64
64
65 counter = 0
65 counter = 0
66 for y in range(nrow):
66 for y in range(nrow):
67 for x in range(ncol):
67 for x in range(ncol):
68
68
69 if counter >= self.nplots:
69 if counter >= self.nplots:
70 break
70 break
71
71
72 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
72 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
73
73
74 if showprofile:
74 if showprofile:
75 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
75 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
76
76
77 counter += 1
77 counter += 1
78
78
79
79
80 def run(self, dataOut, id, wintitle="", channelList=None,
80 def run(self, dataOut, id, wintitle="", channelList=None,
81 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
81 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
82 figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
82 figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
83 server=None, folder=None, username=None, password=None,
83 server=None, folder=None, username=None, password=None,
84 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
84 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
85
85
86 """
86 """
87
87
88 Input:
88 Input:
89 dataOut :
89 dataOut :
90 id :
90 id :
91 wintitle :
91 wintitle :
92 channelList :
92 channelList :
93 xmin : None,
93 xmin : None,
94 xmax : None,
94 xmax : None,
95 ymin : None,
95 ymin : None,
96 ymax : None,
96 ymax : None,
97 """
97 """
98
98
99 if dataOut.realtime:
99 if dataOut.realtime:
100 if not(isRealtime(utcdatatime = dataOut.utctime)):
100 if not(isRealtime(utcdatatime = dataOut.utctime)):
101 print 'Skipping this plot function'
101 print('Skipping this plot function')
102 return
102 return
103
103
104 if channelList == None:
104 if channelList == None:
105 channelIndexList = dataOut.channelIndexList
105 channelIndexList = dataOut.channelIndexList
106 else:
106 else:
107 channelIndexList = []
107 channelIndexList = []
108 for channel in channelList:
108 for channel in channelList:
109 if channel not in dataOut.channelList:
109 if channel not in dataOut.channelList:
110 raise ValueError, "Channel %d is not in dataOut.channelList"
110 raise ValueError("Channel %d is not in dataOut.channelList")
111 channelIndexList.append(dataOut.channelList.index(channel))
111 channelIndexList.append(dataOut.channelList.index(channel))
112
112
113 # x = dataOut.heightList
113 # x = dataOut.heightList
114 c = 3E8
114 c = 3E8
115 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
115 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
116 #deberia cambiar para el caso de 1Mhz y 100KHz
116 #deberia cambiar para el caso de 1Mhz y 100KHz
117 x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000))
117 x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000))
118 #para 1Mhz descomentar la siguiente linea
118 #para 1Mhz descomentar la siguiente linea
119 #x= x/(10000.0)
119 #x= x/(10000.0)
120 # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
120 # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
121 # y = y.real
121 # y = y.real
122 factor = dataOut.normFactor
122 factor = dataOut.normFactor
123 data = dataOut.data_spc / factor
123 data = dataOut.data_spc / factor
124 datadB = 10.*numpy.log10(data)
124 datadB = 10.*numpy.log10(data)
125 y = datadB
125 y = datadB
126
126
127 #thisDatetime = dataOut.datatime
127 #thisDatetime = dataOut.datatime
128 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
128 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
129 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
129 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
130 xlabel = ""
130 xlabel = ""
131 #para 1Mhz descomentar la siguiente linea
131 #para 1Mhz descomentar la siguiente linea
132 #xlabel = "Frequency x 10000"
132 #xlabel = "Frequency x 10000"
133 ylabel = "Intensity (dB)"
133 ylabel = "Intensity (dB)"
134
134
135 if not self.isConfig:
135 if not self.isConfig:
136 nplots = len(channelIndexList)
136 nplots = len(channelIndexList)
137
137
138 self.setup(id=id,
138 self.setup(id=id,
139 nplots=nplots,
139 nplots=nplots,
140 wintitle=wintitle,
140 wintitle=wintitle,
141 show=show)
141 show=show)
142
142
143 if xmin == None: xmin = numpy.nanmin(x)
143 if xmin == None: xmin = numpy.nanmin(x)
144 if xmax == None: xmax = numpy.nanmax(x)
144 if xmax == None: xmax = numpy.nanmax(x)
145 if ymin == None: ymin = numpy.nanmin(y)
145 if ymin == None: ymin = numpy.nanmin(y)
146 if ymax == None: ymax = numpy.nanmax(y)
146 if ymax == None: ymax = numpy.nanmax(y)
147
147
148 self.FTP_WEI = ftp_wei
148 self.FTP_WEI = ftp_wei
149 self.EXP_CODE = exp_code
149 self.EXP_CODE = exp_code
150 self.SUB_EXP_CODE = sub_exp_code
150 self.SUB_EXP_CODE = sub_exp_code
151 self.PLOT_POS = plot_pos
151 self.PLOT_POS = plot_pos
152
152
153 self.isConfig = True
153 self.isConfig = True
154
154
155 self.setWinTitle(title)
155 self.setWinTitle(title)
156
156
157 for i in range(len(self.axesList)):
157 for i in range(len(self.axesList)):
158 ychannel = y[i,:]
158 ychannel = y[i,:]
159 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
159 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
160 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[channelIndexList[i]], numpy.max(ychannel), str_datetime)
160 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[channelIndexList[i]], numpy.max(ychannel), str_datetime)
161 axes = self.axesList[i]
161 axes = self.axesList[i]
162 axes.pline(x, ychannel,
162 axes.pline(x, ychannel,
163 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
163 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
164 xlabel=xlabel, ylabel=ylabel, title=title, grid='both')
164 xlabel=xlabel, ylabel=ylabel, title=title, grid='both')
165
165
166
166
167 self.draw()
167 self.draw()
168
168
169 self.save(figpath=figpath,
169 self.save(figpath=figpath,
170 figfile=figfile,
170 figfile=figfile,
171 save=save,
171 save=save,
172 ftp=ftp,
172 ftp=ftp,
173 wr_period=wr_period,
173 wr_period=wr_period,
174 thisDatetime=thisDatetime)
174 thisDatetime=thisDatetime)
175
175
176 class RTIfromSpectraHeis(Figure):
176 class RTIfromSpectraHeis(Figure):
177
177
178 isConfig = None
178 isConfig = None
179 __nsubplots = None
179 __nsubplots = None
180
180
181 PREFIX = 'rtinoise'
181 PREFIX = 'rtinoise'
182
182
183 def __init__(self, **kwargs):
183 def __init__(self, **kwargs):
184 Figure.__init__(self, **kwargs)
184 Figure.__init__(self, **kwargs)
185 self.timerange = 24*60*60
185 self.timerange = 24*60*60
186 self.isConfig = False
186 self.isConfig = False
187 self.__nsubplots = 1
187 self.__nsubplots = 1
188
188
189 self.WIDTH = 820
189 self.WIDTH = 820
190 self.HEIGHT = 200
190 self.HEIGHT = 200
191 self.WIDTHPROF = 120
191 self.WIDTHPROF = 120
192 self.HEIGHTPROF = 0
192 self.HEIGHTPROF = 0
193 self.counter_imagwr = 0
193 self.counter_imagwr = 0
194 self.xdata = None
194 self.xdata = None
195 self.ydata = None
195 self.ydata = None
196 self.figfile = None
196 self.figfile = None
197
197
198 self.PLOT_CODE = RTI_CODE
198 self.PLOT_CODE = RTI_CODE
199
199
200 def getSubplots(self):
200 def getSubplots(self):
201
201
202 ncol = 1
202 ncol = 1
203 nrow = 1
203 nrow = 1
204
204
205 return nrow, ncol
205 return nrow, ncol
206
206
207 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
207 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
208
208
209 self.__showprofile = showprofile
209 self.__showprofile = showprofile
210 self.nplots = nplots
210 self.nplots = nplots
211
211
212 ncolspan = 7
212 ncolspan = 7
213 colspan = 6
213 colspan = 6
214 self.__nsubplots = 2
214 self.__nsubplots = 2
215
215
216 self.createFigure(id = id,
216 self.createFigure(id = id,
217 wintitle = wintitle,
217 wintitle = wintitle,
218 widthplot = self.WIDTH+self.WIDTHPROF,
218 widthplot = self.WIDTH+self.WIDTHPROF,
219 heightplot = self.HEIGHT+self.HEIGHTPROF,
219 heightplot = self.HEIGHT+self.HEIGHTPROF,
220 show = show)
220 show = show)
221
221
222 nrow, ncol = self.getSubplots()
222 nrow, ncol = self.getSubplots()
223
223
224 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
224 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
225
225
226
226
227 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
227 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
228 xmin=None, xmax=None, ymin=None, ymax=None,
228 xmin=None, xmax=None, ymin=None, ymax=None,
229 timerange=None,
229 timerange=None,
230 save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
230 save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
231 server=None, folder=None, username=None, password=None,
231 server=None, folder=None, username=None, password=None,
232 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
232 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
233
233
234 if channelList == None:
234 if channelList == None:
235 channelIndexList = dataOut.channelIndexList
235 channelIndexList = dataOut.channelIndexList
236 channelList = dataOut.channelList
236 channelList = dataOut.channelList
237 else:
237 else:
238 channelIndexList = []
238 channelIndexList = []
239 for channel in channelList:
239 for channel in channelList:
240 if channel not in dataOut.channelList:
240 if channel not in dataOut.channelList:
241 raise ValueError, "Channel %d is not in dataOut.channelList"
241 raise ValueError("Channel %d is not in dataOut.channelList")
242 channelIndexList.append(dataOut.channelList.index(channel))
242 channelIndexList.append(dataOut.channelList.index(channel))
243
243
244 if timerange != None:
244 if timerange != None:
245 self.timerange = timerange
245 self.timerange = timerange
246
246
247 x = dataOut.getTimeRange()
247 x = dataOut.getTimeRange()
248 y = dataOut.getHeiRange()
248 y = dataOut.getHeiRange()
249
249
250 factor = dataOut.normFactor
250 factor = dataOut.normFactor
251 data = dataOut.data_spc / factor
251 data = dataOut.data_spc / factor
252 data = numpy.average(data,axis=1)
252 data = numpy.average(data,axis=1)
253 datadB = 10*numpy.log10(data)
253 datadB = 10*numpy.log10(data)
254
254
255 # factor = dataOut.normFactor
255 # factor = dataOut.normFactor
256 # noise = dataOut.getNoise()/factor
256 # noise = dataOut.getNoise()/factor
257 # noisedB = 10*numpy.log10(noise)
257 # noisedB = 10*numpy.log10(noise)
258
258
259 #thisDatetime = dataOut.datatime
259 #thisDatetime = dataOut.datatime
260 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
260 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
261 title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
261 title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
262 xlabel = "Local Time"
262 xlabel = "Local Time"
263 ylabel = "Intensity (dB)"
263 ylabel = "Intensity (dB)"
264
264
265 if not self.isConfig:
265 if not self.isConfig:
266
266
267 nplots = 1
267 nplots = 1
268
268
269 self.setup(id=id,
269 self.setup(id=id,
270 nplots=nplots,
270 nplots=nplots,
271 wintitle=wintitle,
271 wintitle=wintitle,
272 showprofile=showprofile,
272 showprofile=showprofile,
273 show=show)
273 show=show)
274
274
275 self.tmin, self.tmax = self.getTimeLim(x, xmin, xmax)
275 self.tmin, self.tmax = self.getTimeLim(x, xmin, xmax)
276
276
277 if ymin == None: ymin = numpy.nanmin(datadB)
277 if ymin == None: ymin = numpy.nanmin(datadB)
278 if ymax == None: ymax = numpy.nanmax(datadB)
278 if ymax == None: ymax = numpy.nanmax(datadB)
279
279
280 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
280 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
281 self.isConfig = True
281 self.isConfig = True
282 self.figfile = figfile
282 self.figfile = figfile
283 self.xdata = numpy.array([])
283 self.xdata = numpy.array([])
284 self.ydata = numpy.array([])
284 self.ydata = numpy.array([])
285
285
286 self.FTP_WEI = ftp_wei
286 self.FTP_WEI = ftp_wei
287 self.EXP_CODE = exp_code
287 self.EXP_CODE = exp_code
288 self.SUB_EXP_CODE = sub_exp_code
288 self.SUB_EXP_CODE = sub_exp_code
289 self.PLOT_POS = plot_pos
289 self.PLOT_POS = plot_pos
290
290
291 self.setWinTitle(title)
291 self.setWinTitle(title)
292
292
293
293
294 # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y"))
294 # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y"))
295 title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
295 title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
296
296
297 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
297 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
298 axes = self.axesList[0]
298 axes = self.axesList[0]
299
299
300 self.xdata = numpy.hstack((self.xdata, x[0:1]))
300 self.xdata = numpy.hstack((self.xdata, x[0:1]))
301
301
302 if len(self.ydata)==0:
302 if len(self.ydata)==0:
303 self.ydata = datadB[channelIndexList].reshape(-1,1)
303 self.ydata = datadB[channelIndexList].reshape(-1,1)
304 else:
304 else:
305 self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1)))
305 self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1)))
306
306
307
307
308 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
308 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
309 xmin=self.tmin, xmax=self.tmax, ymin=ymin, ymax=ymax,
309 xmin=self.tmin, xmax=self.tmax, ymin=ymin, ymax=ymax,
310 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both',
310 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both',
311 XAxisAsTime=True
311 XAxisAsTime=True
312 )
312 )
313
313
314 self.draw()
314 self.draw()
315
315
316 update_figfile = False
316 update_figfile = False
317
317
318 if dataOut.ltctime >= self.tmax:
318 if dataOut.ltctime >= self.tmax:
319 self.counter_imagwr = wr_period
319 self.counter_imagwr = wr_period
320 self.isConfig = False
320 self.isConfig = False
321 update_figfile = True
321 update_figfile = True
322
322
323 self.save(figpath=figpath,
323 self.save(figpath=figpath,
324 figfile=figfile,
324 figfile=figfile,
325 save=save,
325 save=save,
326 ftp=ftp,
326 ftp=ftp,
327 wr_period=wr_period,
327 wr_period=wr_period,
328 thisDatetime=thisDatetime,
328 thisDatetime=thisDatetime,
329 update_figfile=update_figfile)
329 update_figfile=update_figfile) No newline at end of file
@@ -1,2151 +1,2151
1 import os
1 import os
2 import datetime
2 import datetime
3 import numpy
3 import numpy
4 import inspect
4 import inspect
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
8
9 class FitGauPlot(Figure):
9 class FitGauPlot(Figure):
10
10
11 isConfig = None
11 isConfig = None
12 __nsubplots = None
12 __nsubplots = None
13
13
14 WIDTHPROF = None
14 WIDTHPROF = None
15 HEIGHTPROF = None
15 HEIGHTPROF = None
16 PREFIX = 'fitgau'
16 PREFIX = 'fitgau'
17
17
18 def __init__(self, **kwargs):
18 def __init__(self, **kwargs):
19 Figure.__init__(self, **kwargs)
19 Figure.__init__(self, **kwargs)
20 self.isConfig = False
20 self.isConfig = False
21 self.__nsubplots = 1
21 self.__nsubplots = 1
22
22
23 self.WIDTH = 250
23 self.WIDTH = 250
24 self.HEIGHT = 250
24 self.HEIGHT = 250
25 self.WIDTHPROF = 120
25 self.WIDTHPROF = 120
26 self.HEIGHTPROF = 0
26 self.HEIGHTPROF = 0
27 self.counter_imagwr = 0
27 self.counter_imagwr = 0
28
28
29 self.PLOT_CODE = SPEC_CODE
29 self.PLOT_CODE = SPEC_CODE
30
30
31 self.FTP_WEI = None
31 self.FTP_WEI = None
32 self.EXP_CODE = None
32 self.EXP_CODE = None
33 self.SUB_EXP_CODE = None
33 self.SUB_EXP_CODE = None
34 self.PLOT_POS = None
34 self.PLOT_POS = None
35
35
36 self.__xfilter_ena = False
36 self.__xfilter_ena = False
37 self.__yfilter_ena = False
37 self.__yfilter_ena = False
38
38
39 def getSubplots(self):
39 def getSubplots(self):
40
40
41 ncol = int(numpy.sqrt(self.nplots)+0.9)
41 ncol = int(numpy.sqrt(self.nplots)+0.9)
42 nrow = int(self.nplots*1./ncol + 0.9)
42 nrow = int(self.nplots*1./ncol + 0.9)
43
43
44 return nrow, ncol
44 return nrow, ncol
45
45
46 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
46 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
47
47
48 self.__showprofile = showprofile
48 self.__showprofile = showprofile
49 self.nplots = nplots
49 self.nplots = nplots
50
50
51 ncolspan = 1
51 ncolspan = 1
52 colspan = 1
52 colspan = 1
53 if showprofile:
53 if showprofile:
54 ncolspan = 3
54 ncolspan = 3
55 colspan = 2
55 colspan = 2
56 self.__nsubplots = 2
56 self.__nsubplots = 2
57
57
58 self.createFigure(id = id,
58 self.createFigure(id = id,
59 wintitle = wintitle,
59 wintitle = wintitle,
60 widthplot = self.WIDTH + self.WIDTHPROF,
60 widthplot = self.WIDTH + self.WIDTHPROF,
61 heightplot = self.HEIGHT + self.HEIGHTPROF,
61 heightplot = self.HEIGHT + self.HEIGHTPROF,
62 show=show)
62 show=show)
63
63
64 nrow, ncol = self.getSubplots()
64 nrow, ncol = self.getSubplots()
65
65
66 counter = 0
66 counter = 0
67 for y in range(nrow):
67 for y in range(nrow):
68 for x in range(ncol):
68 for x in range(ncol):
69
69
70 if counter >= self.nplots:
70 if counter >= self.nplots:
71 break
71 break
72
72
73 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
73 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
74
74
75 if showprofile:
75 if showprofile:
76 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
76 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
77
77
78 counter += 1
78 counter += 1
79
79
80 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
80 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
81 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
81 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
82 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
82 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
83 server=None, folder=None, username=None, password=None,
83 server=None, folder=None, username=None, password=None,
84 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
84 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
85 xaxis="frequency", colormap='jet', normFactor=None , GauSelector = 1):
85 xaxis="frequency", colormap='jet', normFactor=None , GauSelector = 1):
86
86
87 """
87 """
88
88
89 Input:
89 Input:
90 dataOut :
90 dataOut :
91 id :
91 id :
92 wintitle :
92 wintitle :
93 channelList :
93 channelList :
94 showProfile :
94 showProfile :
95 xmin : None,
95 xmin : None,
96 xmax : None,
96 xmax : None,
97 ymin : None,
97 ymin : None,
98 ymax : None,
98 ymax : None,
99 zmin : None,
99 zmin : None,
100 zmax : None
100 zmax : None
101 """
101 """
102 if realtime:
102 if realtime:
103 if not(isRealtime(utcdatatime = dataOut.utctime)):
103 if not(isRealtime(utcdatatime = dataOut.utctime)):
104 print 'Skipping this plot function'
104 print('Skipping this plot function')
105 return
105 return
106
106
107 if channelList == None:
107 if channelList == None:
108 channelIndexList = dataOut.channelIndexList
108 channelIndexList = dataOut.channelIndexList
109 else:
109 else:
110 channelIndexList = []
110 channelIndexList = []
111 for channel in channelList:
111 for channel in channelList:
112 if channel not in dataOut.channelList:
112 if channel not in dataOut.channelList:
113 raise ValueError, "Channel %d is not in dataOut.channelList" %channel
113 raise ValueError("Channel %d is not in dataOut.channelList" %channel)
114 channelIndexList.append(dataOut.channelList.index(channel))
114 channelIndexList.append(dataOut.channelList.index(channel))
115
115
116 # if normFactor is None:
116 # if normFactor is None:
117 # factor = dataOut.normFactor
117 # factor = dataOut.normFactor
118 # else:
118 # else:
119 # factor = normFactor
119 # factor = normFactor
120 if xaxis == "frequency":
120 if xaxis == "frequency":
121 x = dataOut.spc_range[0]
121 x = dataOut.spc_range[0]
122 xlabel = "Frequency (kHz)"
122 xlabel = "Frequency (kHz)"
123
123
124 elif xaxis == "time":
124 elif xaxis == "time":
125 x = dataOut.spc_range[1]
125 x = dataOut.spc_range[1]
126 xlabel = "Time (ms)"
126 xlabel = "Time (ms)"
127
127
128 else:
128 else:
129 x = dataOut.spc_range[2]
129 x = dataOut.spc_range[2]
130 xlabel = "Velocity (m/s)"
130 xlabel = "Velocity (m/s)"
131
131
132 ylabel = "Range (Km)"
132 ylabel = "Range (Km)"
133
133
134 y = dataOut.getHeiRange()
134 y = dataOut.getHeiRange()
135
135
136 z = dataOut.GauSPC[:,GauSelector,:,:] #GauSelector] #dataOut.data_spc/factor
136 z = dataOut.GauSPC[:,GauSelector,:,:] #GauSelector] #dataOut.data_spc/factor
137 print 'GausSPC', z[0,32,10:40]
137 print('GausSPC', z[0,32,10:40])
138 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
138 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
139 zdB = 10*numpy.log10(z)
139 zdB = 10*numpy.log10(z)
140
140
141 avg = numpy.average(z, axis=1)
141 avg = numpy.average(z, axis=1)
142 avgdB = 10*numpy.log10(avg)
142 avgdB = 10*numpy.log10(avg)
143
143
144 noise = dataOut.spc_noise
144 noise = dataOut.spc_noise
145 noisedB = 10*numpy.log10(noise)
145 noisedB = 10*numpy.log10(noise)
146
146
147 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
147 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
148 title = wintitle + " Spectra"
148 title = wintitle + " Spectra"
149 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
149 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
150 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
150 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
151
151
152 if not self.isConfig:
152 if not self.isConfig:
153
153
154 nplots = len(channelIndexList)
154 nplots = len(channelIndexList)
155
155
156 self.setup(id=id,
156 self.setup(id=id,
157 nplots=nplots,
157 nplots=nplots,
158 wintitle=wintitle,
158 wintitle=wintitle,
159 showprofile=showprofile,
159 showprofile=showprofile,
160 show=show)
160 show=show)
161
161
162 if xmin == None: xmin = numpy.nanmin(x)
162 if xmin == None: xmin = numpy.nanmin(x)
163 if xmax == None: xmax = numpy.nanmax(x)
163 if xmax == None: xmax = numpy.nanmax(x)
164 if ymin == None: ymin = numpy.nanmin(y)
164 if ymin == None: ymin = numpy.nanmin(y)
165 if ymax == None: ymax = numpy.nanmax(y)
165 if ymax == None: ymax = numpy.nanmax(y)
166 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
166 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
167 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
167 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
168
168
169 self.FTP_WEI = ftp_wei
169 self.FTP_WEI = ftp_wei
170 self.EXP_CODE = exp_code
170 self.EXP_CODE = exp_code
171 self.SUB_EXP_CODE = sub_exp_code
171 self.SUB_EXP_CODE = sub_exp_code
172 self.PLOT_POS = plot_pos
172 self.PLOT_POS = plot_pos
173
173
174 self.isConfig = True
174 self.isConfig = True
175
175
176 self.setWinTitle(title)
176 self.setWinTitle(title)
177
177
178 for i in range(self.nplots):
178 for i in range(self.nplots):
179 index = channelIndexList[i]
179 index = channelIndexList[i]
180 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
180 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
181 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
181 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
182 if len(dataOut.beam.codeList) != 0:
182 if len(dataOut.beam.codeList) != 0:
183 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)
183 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)
184
184
185 axes = self.axesList[i*self.__nsubplots]
185 axes = self.axesList[i*self.__nsubplots]
186 axes.pcolor(x, y, zdB[index,:,:],
186 axes.pcolor(x, y, zdB[index,:,:],
187 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
187 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
188 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
188 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
189 ticksize=9, cblabel='')
189 ticksize=9, cblabel='')
190
190
191 if self.__showprofile:
191 if self.__showprofile:
192 axes = self.axesList[i*self.__nsubplots +1]
192 axes = self.axesList[i*self.__nsubplots +1]
193 axes.pline(avgdB[index,:], y,
193 axes.pline(avgdB[index,:], y,
194 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
194 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
195 xlabel='dB', ylabel='', title='',
195 xlabel='dB', ylabel='', title='',
196 ytick_visible=False,
196 ytick_visible=False,
197 grid='x')
197 grid='x')
198
198
199 noiseline = numpy.repeat(noisedB[index], len(y))
199 noiseline = numpy.repeat(noisedB[index], len(y))
200 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
200 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
201
201
202 self.draw()
202 self.draw()
203
203
204 if figfile == None:
204 if figfile == None:
205 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
205 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
206 name = str_datetime
206 name = str_datetime
207 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
207 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
208 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
208 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
209 figfile = self.getFilename(name)
209 figfile = self.getFilename(name)
210
210
211 self.save(figpath=figpath,
211 self.save(figpath=figpath,
212 figfile=figfile,
212 figfile=figfile,
213 save=save,
213 save=save,
214 ftp=ftp,
214 ftp=ftp,
215 wr_period=wr_period,
215 wr_period=wr_period,
216 thisDatetime=thisDatetime)
216 thisDatetime=thisDatetime)
217
217
218
218
219
219
220 class MomentsPlot(Figure):
220 class MomentsPlot(Figure):
221
221
222 isConfig = None
222 isConfig = None
223 __nsubplots = None
223 __nsubplots = None
224
224
225 WIDTHPROF = None
225 WIDTHPROF = None
226 HEIGHTPROF = None
226 HEIGHTPROF = None
227 PREFIX = 'prm'
227 PREFIX = 'prm'
228 def __init__(self, **kwargs):
228 def __init__(self, **kwargs):
229 Figure.__init__(self, **kwargs)
229 Figure.__init__(self, **kwargs)
230 self.isConfig = False
230 self.isConfig = False
231 self.__nsubplots = 1
231 self.__nsubplots = 1
232
232
233 self.WIDTH = 280
233 self.WIDTH = 280
234 self.HEIGHT = 250
234 self.HEIGHT = 250
235 self.WIDTHPROF = 120
235 self.WIDTHPROF = 120
236 self.HEIGHTPROF = 0
236 self.HEIGHTPROF = 0
237 self.counter_imagwr = 0
237 self.counter_imagwr = 0
238
238
239 self.PLOT_CODE = MOMENTS_CODE
239 self.PLOT_CODE = MOMENTS_CODE
240
240
241 self.FTP_WEI = None
241 self.FTP_WEI = None
242 self.EXP_CODE = None
242 self.EXP_CODE = None
243 self.SUB_EXP_CODE = None
243 self.SUB_EXP_CODE = None
244 self.PLOT_POS = None
244 self.PLOT_POS = None
245
245
246 def getSubplots(self):
246 def getSubplots(self):
247
247
248 ncol = int(numpy.sqrt(self.nplots)+0.9)
248 ncol = int(numpy.sqrt(self.nplots)+0.9)
249 nrow = int(self.nplots*1./ncol + 0.9)
249 nrow = int(self.nplots*1./ncol + 0.9)
250
250
251 return nrow, ncol
251 return nrow, ncol
252
252
253 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
253 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
254
254
255 self.__showprofile = showprofile
255 self.__showprofile = showprofile
256 self.nplots = nplots
256 self.nplots = nplots
257
257
258 ncolspan = 1
258 ncolspan = 1
259 colspan = 1
259 colspan = 1
260 if showprofile:
260 if showprofile:
261 ncolspan = 3
261 ncolspan = 3
262 colspan = 2
262 colspan = 2
263 self.__nsubplots = 2
263 self.__nsubplots = 2
264
264
265 self.createFigure(id = id,
265 self.createFigure(id = id,
266 wintitle = wintitle,
266 wintitle = wintitle,
267 widthplot = self.WIDTH + self.WIDTHPROF,
267 widthplot = self.WIDTH + self.WIDTHPROF,
268 heightplot = self.HEIGHT + self.HEIGHTPROF,
268 heightplot = self.HEIGHT + self.HEIGHTPROF,
269 show=show)
269 show=show)
270
270
271 nrow, ncol = self.getSubplots()
271 nrow, ncol = self.getSubplots()
272
272
273 counter = 0
273 counter = 0
274 for y in range(nrow):
274 for y in range(nrow):
275 for x in range(ncol):
275 for x in range(ncol):
276
276
277 if counter >= self.nplots:
277 if counter >= self.nplots:
278 break
278 break
279
279
280 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
280 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
281
281
282 if showprofile:
282 if showprofile:
283 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
283 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
284
284
285 counter += 1
285 counter += 1
286
286
287 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
287 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
288 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
288 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
289 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
289 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
290 server=None, folder=None, username=None, password=None,
290 server=None, folder=None, username=None, password=None,
291 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
291 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
292
292
293 """
293 """
294
294
295 Input:
295 Input:
296 dataOut :
296 dataOut :
297 id :
297 id :
298 wintitle :
298 wintitle :
299 channelList :
299 channelList :
300 showProfile :
300 showProfile :
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
308
309 if dataOut.flagNoData:
309 if dataOut.flagNoData:
310 return None
310 return None
311
311
312 if realtime:
312 if realtime:
313 if not(isRealtime(utcdatatime = dataOut.utctime)):
313 if not(isRealtime(utcdatatime = dataOut.utctime)):
314 print 'Skipping this plot function'
314 print('Skipping this plot function')
315 return
315 return
316
316
317 if channelList == None:
317 if channelList == None:
318 channelIndexList = dataOut.channelIndexList
318 channelIndexList = dataOut.channelIndexList
319 else:
319 else:
320 channelIndexList = []
320 channelIndexList = []
321 for channel in channelList:
321 for channel in channelList:
322 if channel not in dataOut.channelList:
322 if channel not in dataOut.channelList:
323 raise ValueError, "Channel %d is not in dataOut.channelList"
323 raise ValueError("Channel %d is not in dataOut.channelList")
324 channelIndexList.append(dataOut.channelList.index(channel))
324 channelIndexList.append(dataOut.channelList.index(channel))
325
325
326 factor = dataOut.normFactor
326 factor = dataOut.normFactor
327 x = dataOut.abscissaList
327 x = dataOut.abscissaList
328 y = dataOut.heightList
328 y = dataOut.heightList
329
329
330 z = dataOut.data_pre[channelIndexList,:,:]/factor
330 z = dataOut.data_pre[channelIndexList,:,:]/factor
331 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
331 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
332 avg = numpy.average(z, axis=1)
332 avg = numpy.average(z, axis=1)
333 noise = dataOut.noise/factor
333 noise = dataOut.noise/factor
334
334
335 zdB = 10*numpy.log10(z)
335 zdB = 10*numpy.log10(z)
336 avgdB = 10*numpy.log10(avg)
336 avgdB = 10*numpy.log10(avg)
337 noisedB = 10*numpy.log10(noise)
337 noisedB = 10*numpy.log10(noise)
338
338
339 #thisDatetime = dataOut.datatime
339 #thisDatetime = dataOut.datatime
340 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
340 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
341 title = wintitle + " Parameters"
341 title = wintitle + " Parameters"
342 xlabel = "Velocity (m/s)"
342 xlabel = "Velocity (m/s)"
343 ylabel = "Range (Km)"
343 ylabel = "Range (Km)"
344
344
345 update_figfile = False
345 update_figfile = False
346
346
347 if not self.isConfig:
347 if not self.isConfig:
348
348
349 nplots = len(channelIndexList)
349 nplots = len(channelIndexList)
350
350
351 self.setup(id=id,
351 self.setup(id=id,
352 nplots=nplots,
352 nplots=nplots,
353 wintitle=wintitle,
353 wintitle=wintitle,
354 showprofile=showprofile,
354 showprofile=showprofile,
355 show=show)
355 show=show)
356
356
357 if xmin == None: xmin = numpy.nanmin(x)
357 if xmin == None: xmin = numpy.nanmin(x)
358 if xmax == None: xmax = numpy.nanmax(x)
358 if xmax == None: xmax = numpy.nanmax(x)
359 if ymin == None: ymin = numpy.nanmin(y)
359 if ymin == None: ymin = numpy.nanmin(y)
360 if ymax == None: ymax = numpy.nanmax(y)
360 if ymax == None: ymax = numpy.nanmax(y)
361 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
361 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
362 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
362 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
363
363
364 self.FTP_WEI = ftp_wei
364 self.FTP_WEI = ftp_wei
365 self.EXP_CODE = exp_code
365 self.EXP_CODE = exp_code
366 self.SUB_EXP_CODE = sub_exp_code
366 self.SUB_EXP_CODE = sub_exp_code
367 self.PLOT_POS = plot_pos
367 self.PLOT_POS = plot_pos
368
368
369 self.isConfig = True
369 self.isConfig = True
370 update_figfile = True
370 update_figfile = True
371
371
372 self.setWinTitle(title)
372 self.setWinTitle(title)
373
373
374 for i in range(self.nplots):
374 for i in range(self.nplots):
375 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
375 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
376 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i], noisedB[i], str_datetime)
376 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i], noisedB[i], str_datetime)
377 axes = self.axesList[i*self.__nsubplots]
377 axes = self.axesList[i*self.__nsubplots]
378 axes.pcolor(x, y, zdB[i,:,:],
378 axes.pcolor(x, y, zdB[i,:,:],
379 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
379 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
380 xlabel=xlabel, ylabel=ylabel, title=title,
380 xlabel=xlabel, ylabel=ylabel, title=title,
381 ticksize=9, cblabel='')
381 ticksize=9, cblabel='')
382 #Mean Line
382 #Mean Line
383 mean = dataOut.data_param[i, 1, :]
383 mean = dataOut.data_param[i, 1, :]
384 axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1)
384 axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1)
385
385
386 if self.__showprofile:
386 if self.__showprofile:
387 axes = self.axesList[i*self.__nsubplots +1]
387 axes = self.axesList[i*self.__nsubplots +1]
388 axes.pline(avgdB[i], y,
388 axes.pline(avgdB[i], y,
389 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
389 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
390 xlabel='dB', ylabel='', title='',
390 xlabel='dB', ylabel='', title='',
391 ytick_visible=False,
391 ytick_visible=False,
392 grid='x')
392 grid='x')
393
393
394 noiseline = numpy.repeat(noisedB[i], len(y))
394 noiseline = numpy.repeat(noisedB[i], len(y))
395 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
395 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
396
396
397 self.draw()
397 self.draw()
398
398
399 self.save(figpath=figpath,
399 self.save(figpath=figpath,
400 figfile=figfile,
400 figfile=figfile,
401 save=save,
401 save=save,
402 ftp=ftp,
402 ftp=ftp,
403 wr_period=wr_period,
403 wr_period=wr_period,
404 thisDatetime=thisDatetime)
404 thisDatetime=thisDatetime)
405
405
406
406
407
407
408 class SkyMapPlot(Figure):
408 class SkyMapPlot(Figure):
409
409
410 __isConfig = None
410 __isConfig = None
411 __nsubplots = None
411 __nsubplots = None
412
412
413 WIDTHPROF = None
413 WIDTHPROF = None
414 HEIGHTPROF = None
414 HEIGHTPROF = None
415 PREFIX = 'mmap'
415 PREFIX = 'mmap'
416
416
417 def __init__(self, **kwargs):
417 def __init__(self, **kwargs):
418 Figure.__init__(self, **kwargs)
418 Figure.__init__(self, **kwargs)
419 self.isConfig = False
419 self.isConfig = False
420 self.__nsubplots = 1
420 self.__nsubplots = 1
421
421
422 # self.WIDTH = 280
422 # self.WIDTH = 280
423 # self.HEIGHT = 250
423 # self.HEIGHT = 250
424 self.WIDTH = 600
424 self.WIDTH = 600
425 self.HEIGHT = 600
425 self.HEIGHT = 600
426 self.WIDTHPROF = 120
426 self.WIDTHPROF = 120
427 self.HEIGHTPROF = 0
427 self.HEIGHTPROF = 0
428 self.counter_imagwr = 0
428 self.counter_imagwr = 0
429
429
430 self.PLOT_CODE = MSKYMAP_CODE
430 self.PLOT_CODE = MSKYMAP_CODE
431
431
432 self.FTP_WEI = None
432 self.FTP_WEI = None
433 self.EXP_CODE = None
433 self.EXP_CODE = None
434 self.SUB_EXP_CODE = None
434 self.SUB_EXP_CODE = None
435 self.PLOT_POS = None
435 self.PLOT_POS = None
436
436
437 def getSubplots(self):
437 def getSubplots(self):
438
438
439 ncol = int(numpy.sqrt(self.nplots)+0.9)
439 ncol = int(numpy.sqrt(self.nplots)+0.9)
440 nrow = int(self.nplots*1./ncol + 0.9)
440 nrow = int(self.nplots*1./ncol + 0.9)
441
441
442 return nrow, ncol
442 return nrow, ncol
443
443
444 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
444 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
445
445
446 self.__showprofile = showprofile
446 self.__showprofile = showprofile
447 self.nplots = nplots
447 self.nplots = nplots
448
448
449 ncolspan = 1
449 ncolspan = 1
450 colspan = 1
450 colspan = 1
451
451
452 self.createFigure(id = id,
452 self.createFigure(id = id,
453 wintitle = wintitle,
453 wintitle = wintitle,
454 widthplot = self.WIDTH, #+ self.WIDTHPROF,
454 widthplot = self.WIDTH, #+ self.WIDTHPROF,
455 heightplot = self.HEIGHT,# + self.HEIGHTPROF,
455 heightplot = self.HEIGHT,# + self.HEIGHTPROF,
456 show=show)
456 show=show)
457
457
458 nrow, ncol = 1,1
458 nrow, ncol = 1,1
459 counter = 0
459 counter = 0
460 x = 0
460 x = 0
461 y = 0
461 y = 0
462 self.addAxes(1, 1, 0, 0, 1, 1, True)
462 self.addAxes(1, 1, 0, 0, 1, 1, True)
463
463
464 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
464 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
465 tmin=0, tmax=24, timerange=None,
465 tmin=0, tmax=24, timerange=None,
466 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
466 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
467 server=None, folder=None, username=None, password=None,
467 server=None, folder=None, username=None, password=None,
468 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
468 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
469
469
470 """
470 """
471
471
472 Input:
472 Input:
473 dataOut :
473 dataOut :
474 id :
474 id :
475 wintitle :
475 wintitle :
476 channelList :
476 channelList :
477 showProfile :
477 showProfile :
478 xmin : None,
478 xmin : None,
479 xmax : None,
479 xmax : None,
480 ymin : None,
480 ymin : None,
481 ymax : None,
481 ymax : None,
482 zmin : None,
482 zmin : None,
483 zmax : None
483 zmax : None
484 """
484 """
485
485
486 arrayParameters = dataOut.data_param
486 arrayParameters = dataOut.data_param
487 error = arrayParameters[:,-1]
487 error = arrayParameters[:,-1]
488 indValid = numpy.where(error == 0)[0]
488 indValid = numpy.where(error == 0)[0]
489 finalMeteor = arrayParameters[indValid,:]
489 finalMeteor = arrayParameters[indValid,:]
490 finalAzimuth = finalMeteor[:,3]
490 finalAzimuth = finalMeteor[:,3]
491 finalZenith = finalMeteor[:,4]
491 finalZenith = finalMeteor[:,4]
492
492
493 x = finalAzimuth*numpy.pi/180
493 x = finalAzimuth*numpy.pi/180
494 y = finalZenith
494 y = finalZenith
495 x1 = [dataOut.ltctime, dataOut.ltctime]
495 x1 = [dataOut.ltctime, dataOut.ltctime]
496
496
497 #thisDatetime = dataOut.datatime
497 #thisDatetime = dataOut.datatime
498 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
498 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
499 title = wintitle + " Parameters"
499 title = wintitle + " Parameters"
500 xlabel = "Zonal Zenith Angle (deg) "
500 xlabel = "Zonal Zenith Angle (deg) "
501 ylabel = "Meridional Zenith Angle (deg)"
501 ylabel = "Meridional Zenith Angle (deg)"
502 update_figfile = False
502 update_figfile = False
503
503
504 if not self.isConfig:
504 if not self.isConfig:
505
505
506 nplots = 1
506 nplots = 1
507
507
508 self.setup(id=id,
508 self.setup(id=id,
509 nplots=nplots,
509 nplots=nplots,
510 wintitle=wintitle,
510 wintitle=wintitle,
511 showprofile=showprofile,
511 showprofile=showprofile,
512 show=show)
512 show=show)
513
513
514 if self.xmin is None and self.xmax is None:
514 if self.xmin is None and self.xmax is None:
515 self.xmin, self.xmax = self.getTimeLim(x1, tmin, tmax, timerange)
515 self.xmin, self.xmax = self.getTimeLim(x1, tmin, tmax, timerange)
516
516
517 if timerange != None:
517 if timerange != None:
518 self.timerange = timerange
518 self.timerange = timerange
519 else:
519 else:
520 self.timerange = self.xmax - self.xmin
520 self.timerange = self.xmax - self.xmin
521
521
522 self.FTP_WEI = ftp_wei
522 self.FTP_WEI = ftp_wei
523 self.EXP_CODE = exp_code
523 self.EXP_CODE = exp_code
524 self.SUB_EXP_CODE = sub_exp_code
524 self.SUB_EXP_CODE = sub_exp_code
525 self.PLOT_POS = plot_pos
525 self.PLOT_POS = plot_pos
526 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
526 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
527 self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
527 self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
528 self.isConfig = True
528 self.isConfig = True
529 update_figfile = True
529 update_figfile = True
530
530
531 self.setWinTitle(title)
531 self.setWinTitle(title)
532
532
533 i = 0
533 i = 0
534 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
534 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
535
535
536 axes = self.axesList[i*self.__nsubplots]
536 axes = self.axesList[i*self.__nsubplots]
537 nevents = axes.x_buffer.shape[0] + x.shape[0]
537 nevents = axes.x_buffer.shape[0] + x.shape[0]
538 title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents)
538 title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents)
539 axes.polar(x, y,
539 axes.polar(x, y,
540 title=title, xlabel=xlabel, ylabel=ylabel,
540 title=title, xlabel=xlabel, ylabel=ylabel,
541 ticksize=9, cblabel='')
541 ticksize=9, cblabel='')
542
542
543 self.draw()
543 self.draw()
544
544
545 self.save(figpath=figpath,
545 self.save(figpath=figpath,
546 figfile=figfile,
546 figfile=figfile,
547 save=save,
547 save=save,
548 ftp=ftp,
548 ftp=ftp,
549 wr_period=wr_period,
549 wr_period=wr_period,
550 thisDatetime=thisDatetime,
550 thisDatetime=thisDatetime,
551 update_figfile=update_figfile)
551 update_figfile=update_figfile)
552
552
553 if dataOut.ltctime >= self.xmax:
553 if dataOut.ltctime >= self.xmax:
554 self.isConfigmagwr = wr_period
554 self.isConfigmagwr = wr_period
555 self.isConfig = False
555 self.isConfig = False
556 update_figfile = True
556 update_figfile = True
557 axes.__firsttime = True
557 axes.__firsttime = True
558 self.xmin += self.timerange
558 self.xmin += self.timerange
559 self.xmax += self.timerange
559 self.xmax += self.timerange
560
560
561
561
562
562
563
563
564 class WindProfilerPlot(Figure):
564 class WindProfilerPlot(Figure):
565
565
566 __isConfig = None
566 __isConfig = None
567 __nsubplots = None
567 __nsubplots = None
568
568
569 WIDTHPROF = None
569 WIDTHPROF = None
570 HEIGHTPROF = None
570 HEIGHTPROF = None
571 PREFIX = 'wind'
571 PREFIX = 'wind'
572
572
573 def __init__(self, **kwargs):
573 def __init__(self, **kwargs):
574 Figure.__init__(self, **kwargs)
574 Figure.__init__(self, **kwargs)
575 self.timerange = None
575 self.timerange = None
576 self.isConfig = False
576 self.isConfig = False
577 self.__nsubplots = 1
577 self.__nsubplots = 1
578
578
579 self.WIDTH = 800
579 self.WIDTH = 800
580 self.HEIGHT = 300
580 self.HEIGHT = 300
581 self.WIDTHPROF = 120
581 self.WIDTHPROF = 120
582 self.HEIGHTPROF = 0
582 self.HEIGHTPROF = 0
583 self.counter_imagwr = 0
583 self.counter_imagwr = 0
584
584
585 self.PLOT_CODE = WIND_CODE
585 self.PLOT_CODE = WIND_CODE
586
586
587 self.FTP_WEI = None
587 self.FTP_WEI = None
588 self.EXP_CODE = None
588 self.EXP_CODE = None
589 self.SUB_EXP_CODE = None
589 self.SUB_EXP_CODE = None
590 self.PLOT_POS = None
590 self.PLOT_POS = None
591 self.tmin = None
591 self.tmin = None
592 self.tmax = None
592 self.tmax = None
593
593
594 self.xmin = None
594 self.xmin = None
595 self.xmax = None
595 self.xmax = None
596
596
597 self.figfile = None
597 self.figfile = None
598
598
599 def getSubplots(self):
599 def getSubplots(self):
600
600
601 ncol = 1
601 ncol = 1
602 nrow = self.nplots
602 nrow = self.nplots
603
603
604 return nrow, ncol
604 return nrow, ncol
605
605
606 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
606 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
607
607
608 self.__showprofile = showprofile
608 self.__showprofile = showprofile
609 self.nplots = nplots
609 self.nplots = nplots
610
610
611 ncolspan = 1
611 ncolspan = 1
612 colspan = 1
612 colspan = 1
613
613
614 self.createFigure(id = id,
614 self.createFigure(id = id,
615 wintitle = wintitle,
615 wintitle = wintitle,
616 widthplot = self.WIDTH + self.WIDTHPROF,
616 widthplot = self.WIDTH + self.WIDTHPROF,
617 heightplot = self.HEIGHT + self.HEIGHTPROF,
617 heightplot = self.HEIGHT + self.HEIGHTPROF,
618 show=show)
618 show=show)
619
619
620 nrow, ncol = self.getSubplots()
620 nrow, ncol = self.getSubplots()
621
621
622 counter = 0
622 counter = 0
623 for y in range(nrow):
623 for y in range(nrow):
624 if counter >= self.nplots:
624 if counter >= self.nplots:
625 break
625 break
626
626
627 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
627 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
628 counter += 1
628 counter += 1
629
629
630 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False',
630 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False',
631 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
631 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
632 zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None,
632 zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None,
633 timerange=None, SNRthresh = None,
633 timerange=None, SNRthresh = None,
634 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
634 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
635 server=None, folder=None, username=None, password=None,
635 server=None, folder=None, username=None, password=None,
636 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
636 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
637 """
637 """
638
638
639 Input:
639 Input:
640 dataOut :
640 dataOut :
641 id :
641 id :
642 wintitle :
642 wintitle :
643 channelList :
643 channelList :
644 showProfile :
644 showProfile :
645 xmin : None,
645 xmin : None,
646 xmax : None,
646 xmax : None,
647 ymin : None,
647 ymin : None,
648 ymax : None,
648 ymax : None,
649 zmin : None,
649 zmin : None,
650 zmax : None
650 zmax : None
651 """
651 """
652
652
653 # if timerange is not None:
653 # if timerange is not None:
654 # self.timerange = timerange
654 # self.timerange = timerange
655 #
655 #
656 # tmin = None
656 # tmin = None
657 # tmax = None
657 # tmax = None
658
658
659 x = dataOut.getTimeRange1(dataOut.paramInterval)
659 x = dataOut.getTimeRange1(dataOut.paramInterval)
660 y = dataOut.heightList
660 y = dataOut.heightList
661 z = dataOut.data_output.copy()
661 z = dataOut.data_output.copy()
662 nplots = z.shape[0] #Number of wind dimensions estimated
662 nplots = z.shape[0] #Number of wind dimensions estimated
663 nplotsw = nplots
663 nplotsw = nplots
664
664
665
665
666 #If there is a SNR function defined
666 #If there is a SNR function defined
667 if dataOut.data_SNR is not None:
667 if dataOut.data_SNR is not None:
668 nplots += 1
668 nplots += 1
669 SNR = dataOut.data_SNR
669 SNR = dataOut.data_SNR
670 SNRavg = numpy.average(SNR, axis=0)
670 SNRavg = numpy.average(SNR, axis=0)
671
671
672 SNRdB = 10*numpy.log10(SNR)
672 SNRdB = 10*numpy.log10(SNR)
673 SNRavgdB = 10*numpy.log10(SNRavg)
673 SNRavgdB = 10*numpy.log10(SNRavg)
674
674
675 if SNRthresh == None: SNRthresh = -5.0
675 if SNRthresh == None: SNRthresh = -5.0
676 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
676 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
677
677
678 for i in range(nplotsw):
678 for i in range(nplotsw):
679 z[i,ind] = numpy.nan
679 z[i,ind] = numpy.nan
680
680
681 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
681 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
682 #thisDatetime = datetime.datetime.now()
682 #thisDatetime = datetime.datetime.now()
683 title = wintitle + "Wind"
683 title = wintitle + "Wind"
684 xlabel = ""
684 xlabel = ""
685 ylabel = "Height (km)"
685 ylabel = "Height (km)"
686 update_figfile = False
686 update_figfile = False
687
687
688 if not self.isConfig:
688 if not self.isConfig:
689
689
690 self.setup(id=id,
690 self.setup(id=id,
691 nplots=nplots,
691 nplots=nplots,
692 wintitle=wintitle,
692 wintitle=wintitle,
693 showprofile=showprofile,
693 showprofile=showprofile,
694 show=show)
694 show=show)
695
695
696 if timerange is not None:
696 if timerange is not None:
697 self.timerange = timerange
697 self.timerange = timerange
698
698
699 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
699 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
700
700
701 if ymin == None: ymin = numpy.nanmin(y)
701 if ymin == None: ymin = numpy.nanmin(y)
702 if ymax == None: ymax = numpy.nanmax(y)
702 if ymax == None: ymax = numpy.nanmax(y)
703
703
704 if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:]))
704 if zmax == None: zmax = numpy.nanmax(abs(z[list(range(2)),:]))
705 #if numpy.isnan(zmax): zmax = 50
705 #if numpy.isnan(zmax): zmax = 50
706 if zmin == None: zmin = -zmax
706 if zmin == None: zmin = -zmax
707
707
708 if nplotsw == 3:
708 if nplotsw == 3:
709 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
709 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
710 if zmin_ver == None: zmin_ver = -zmax_ver
710 if zmin_ver == None: zmin_ver = -zmax_ver
711
711
712 if dataOut.data_SNR is not None:
712 if dataOut.data_SNR is not None:
713 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
713 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
714 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
714 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
715
715
716
716
717 self.FTP_WEI = ftp_wei
717 self.FTP_WEI = ftp_wei
718 self.EXP_CODE = exp_code
718 self.EXP_CODE = exp_code
719 self.SUB_EXP_CODE = sub_exp_code
719 self.SUB_EXP_CODE = sub_exp_code
720 self.PLOT_POS = plot_pos
720 self.PLOT_POS = plot_pos
721
721
722 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
722 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
723 self.isConfig = True
723 self.isConfig = True
724 self.figfile = figfile
724 self.figfile = figfile
725 update_figfile = True
725 update_figfile = True
726
726
727 self.setWinTitle(title)
727 self.setWinTitle(title)
728
728
729 if ((self.xmax - x[1]) < (x[1]-x[0])):
729 if ((self.xmax - x[1]) < (x[1]-x[0])):
730 x[1] = self.xmax
730 x[1] = self.xmax
731
731
732 strWind = ['Zonal', 'Meridional', 'Vertical']
732 strWind = ['Zonal', 'Meridional', 'Vertical']
733 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
733 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
734 zmaxVector = [zmax, zmax, zmax_ver]
734 zmaxVector = [zmax, zmax, zmax_ver]
735 zminVector = [zmin, zmin, zmin_ver]
735 zminVector = [zmin, zmin, zmin_ver]
736 windFactor = [1,1,100]
736 windFactor = [1,1,100]
737
737
738 for i in range(nplotsw):
738 for i in range(nplotsw):
739
739
740 title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
740 title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
741 axes = self.axesList[i*self.__nsubplots]
741 axes = self.axesList[i*self.__nsubplots]
742
742
743 z1 = z[i,:].reshape((1,-1))*windFactor[i]
743 z1 = z[i,:].reshape((1,-1))*windFactor[i]
744 #z1=numpy.ma.masked_where(z1==0.,z1)
744 #z1=numpy.ma.masked_where(z1==0.,z1)
745
745
746 axes.pcolorbuffer(x, y, z1,
746 axes.pcolorbuffer(x, y, z1,
747 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
747 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
748 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
748 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
749 ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="seismic" )
749 ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="seismic" )
750
750
751 if dataOut.data_SNR is not None:
751 if dataOut.data_SNR is not None:
752 i += 1
752 i += 1
753 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
753 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
754 axes = self.axesList[i*self.__nsubplots]
754 axes = self.axesList[i*self.__nsubplots]
755 SNRavgdB = SNRavgdB.reshape((1,-1))
755 SNRavgdB = SNRavgdB.reshape((1,-1))
756 axes.pcolorbuffer(x, y, SNRavgdB,
756 axes.pcolorbuffer(x, y, SNRavgdB,
757 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
757 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
758 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
758 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
759 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
759 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
760
760
761 self.draw()
761 self.draw()
762
762
763 self.save(figpath=figpath,
763 self.save(figpath=figpath,
764 figfile=figfile,
764 figfile=figfile,
765 save=save,
765 save=save,
766 ftp=ftp,
766 ftp=ftp,
767 wr_period=wr_period,
767 wr_period=wr_period,
768 thisDatetime=thisDatetime,
768 thisDatetime=thisDatetime,
769 update_figfile=update_figfile)
769 update_figfile=update_figfile)
770
770
771 if dataOut.ltctime + dataOut.paramInterval >= self.xmax:
771 if dataOut.ltctime + dataOut.paramInterval >= self.xmax:
772 self.counter_imagwr = wr_period
772 self.counter_imagwr = wr_period
773 self.isConfig = False
773 self.isConfig = False
774 update_figfile = True
774 update_figfile = True
775
775
776
776
777 class ParametersPlot(Figure):
777 class ParametersPlot(Figure):
778
778
779 __isConfig = None
779 __isConfig = None
780 __nsubplots = None
780 __nsubplots = None
781
781
782 WIDTHPROF = None
782 WIDTHPROF = None
783 HEIGHTPROF = None
783 HEIGHTPROF = None
784 PREFIX = 'param'
784 PREFIX = 'param'
785
785
786 nplots = None
786 nplots = None
787 nchan = None
787 nchan = None
788
788
789 def __init__(self, **kwargs):
789 def __init__(self, **kwargs):
790 Figure.__init__(self, **kwargs)
790 Figure.__init__(self, **kwargs)
791 self.timerange = None
791 self.timerange = None
792 self.isConfig = False
792 self.isConfig = False
793 self.__nsubplots = 1
793 self.__nsubplots = 1
794
794
795 self.WIDTH = 800
795 self.WIDTH = 800
796 self.HEIGHT = 180
796 self.HEIGHT = 180
797 self.WIDTHPROF = 120
797 self.WIDTHPROF = 120
798 self.HEIGHTPROF = 0
798 self.HEIGHTPROF = 0
799 self.counter_imagwr = 0
799 self.counter_imagwr = 0
800
800
801 self.PLOT_CODE = RTI_CODE
801 self.PLOT_CODE = RTI_CODE
802
802
803 self.FTP_WEI = None
803 self.FTP_WEI = None
804 self.EXP_CODE = None
804 self.EXP_CODE = None
805 self.SUB_EXP_CODE = None
805 self.SUB_EXP_CODE = None
806 self.PLOT_POS = None
806 self.PLOT_POS = None
807 self.tmin = None
807 self.tmin = None
808 self.tmax = None
808 self.tmax = None
809
809
810 self.xmin = None
810 self.xmin = None
811 self.xmax = None
811 self.xmax = None
812
812
813 self.figfile = None
813 self.figfile = None
814
814
815 def getSubplots(self):
815 def getSubplots(self):
816
816
817 ncol = 1
817 ncol = 1
818 nrow = self.nplots
818 nrow = self.nplots
819
819
820 return nrow, ncol
820 return nrow, ncol
821
821
822 def setup(self, id, nplots, wintitle, show=True):
822 def setup(self, id, nplots, wintitle, show=True):
823
823
824 self.nplots = nplots
824 self.nplots = nplots
825
825
826 ncolspan = 1
826 ncolspan = 1
827 colspan = 1
827 colspan = 1
828
828
829 self.createFigure(id = id,
829 self.createFigure(id = id,
830 wintitle = wintitle,
830 wintitle = wintitle,
831 widthplot = self.WIDTH + self.WIDTHPROF,
831 widthplot = self.WIDTH + self.WIDTHPROF,
832 heightplot = self.HEIGHT + self.HEIGHTPROF,
832 heightplot = self.HEIGHT + self.HEIGHTPROF,
833 show=show)
833 show=show)
834
834
835 nrow, ncol = self.getSubplots()
835 nrow, ncol = self.getSubplots()
836
836
837 counter = 0
837 counter = 0
838 for y in range(nrow):
838 for y in range(nrow):
839 for x in range(ncol):
839 for x in range(ncol):
840
840
841 if counter >= self.nplots:
841 if counter >= self.nplots:
842 break
842 break
843
843
844 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
844 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
845
845
846 counter += 1
846 counter += 1
847
847
848 def run(self, dataOut, id, wintitle="", channelList=None, paramIndex = 0, colormap="jet",
848 def run(self, dataOut, id, wintitle="", channelList=None, paramIndex = 0, colormap="jet",
849 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, timerange=None,
849 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, timerange=None,
850 showSNR=False, SNRthresh = -numpy.inf, SNRmin=None, SNRmax=None,
850 showSNR=False, SNRthresh = -numpy.inf, SNRmin=None, SNRmax=None,
851 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
851 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
852 server=None, folder=None, username=None, password=None,
852 server=None, folder=None, username=None, password=None,
853 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, HEIGHT=None):
853 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, HEIGHT=None):
854 """
854 """
855
855
856 Input:
856 Input:
857 dataOut :
857 dataOut :
858 id :
858 id :
859 wintitle :
859 wintitle :
860 channelList :
860 channelList :
861 showProfile :
861 showProfile :
862 xmin : None,
862 xmin : None,
863 xmax : None,
863 xmax : None,
864 ymin : None,
864 ymin : None,
865 ymax : None,
865 ymax : None,
866 zmin : None,
866 zmin : None,
867 zmax : None
867 zmax : None
868 """
868 """
869
869
870 if HEIGHT is not None:
870 if HEIGHT is not None:
871 self.HEIGHT = HEIGHT
871 self.HEIGHT = HEIGHT
872
872
873
873
874 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
874 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
875 return
875 return
876
876
877 if channelList == None:
877 if channelList == None:
878 channelIndexList = range(dataOut.data_param.shape[0])
878 channelIndexList = list(range(dataOut.data_param.shape[0]))
879 else:
879 else:
880 channelIndexList = []
880 channelIndexList = []
881 for channel in channelList:
881 for channel in channelList:
882 if channel not in dataOut.channelList:
882 if channel not in dataOut.channelList:
883 raise ValueError, "Channel %d is not in dataOut.channelList"
883 raise ValueError("Channel %d is not in dataOut.channelList")
884 channelIndexList.append(dataOut.channelList.index(channel))
884 channelIndexList.append(dataOut.channelList.index(channel))
885
885
886 x = dataOut.getTimeRange1(dataOut.paramInterval)
886 x = dataOut.getTimeRange1(dataOut.paramInterval)
887 y = dataOut.getHeiRange()
887 y = dataOut.getHeiRange()
888
888
889 if dataOut.data_param.ndim == 3:
889 if dataOut.data_param.ndim == 3:
890 z = dataOut.data_param[channelIndexList,paramIndex,:]
890 z = dataOut.data_param[channelIndexList,paramIndex,:]
891 else:
891 else:
892 z = dataOut.data_param[channelIndexList,:]
892 z = dataOut.data_param[channelIndexList,:]
893
893
894 if showSNR:
894 if showSNR:
895 #SNR data
895 #SNR data
896 SNRarray = dataOut.data_SNR[channelIndexList,:]
896 SNRarray = dataOut.data_SNR[channelIndexList,:]
897 SNRdB = 10*numpy.log10(SNRarray)
897 SNRdB = 10*numpy.log10(SNRarray)
898 ind = numpy.where(SNRdB < SNRthresh)
898 ind = numpy.where(SNRdB < SNRthresh)
899 z[ind] = numpy.nan
899 z[ind] = numpy.nan
900
900
901 thisDatetime = dataOut.datatime
901 thisDatetime = dataOut.datatime
902 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
902 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
903 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
903 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
904 xlabel = ""
904 xlabel = ""
905 ylabel = "Range (Km)"
905 ylabel = "Range (Km)"
906
906
907 update_figfile = False
907 update_figfile = False
908
908
909 if not self.isConfig:
909 if not self.isConfig:
910
910
911 nchan = len(channelIndexList)
911 nchan = len(channelIndexList)
912 self.nchan = nchan
912 self.nchan = nchan
913 self.plotFact = 1
913 self.plotFact = 1
914 nplots = nchan
914 nplots = nchan
915
915
916 if showSNR:
916 if showSNR:
917 nplots = nchan*2
917 nplots = nchan*2
918 self.plotFact = 2
918 self.plotFact = 2
919 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
919 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
920 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
920 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
921
921
922 self.setup(id=id,
922 self.setup(id=id,
923 nplots=nplots,
923 nplots=nplots,
924 wintitle=wintitle,
924 wintitle=wintitle,
925 show=show)
925 show=show)
926
926
927 if timerange != None:
927 if timerange != None:
928 self.timerange = timerange
928 self.timerange = timerange
929
929
930 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
930 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
931
931
932 if ymin == None: ymin = numpy.nanmin(y)
932 if ymin == None: ymin = numpy.nanmin(y)
933 if ymax == None: ymax = numpy.nanmax(y)
933 if ymax == None: ymax = numpy.nanmax(y)
934 if zmin == None: zmin = numpy.nanmin(z)
934 if zmin == None: zmin = numpy.nanmin(z)
935 if zmax == None: zmax = numpy.nanmax(z)
935 if zmax == None: zmax = numpy.nanmax(z)
936
936
937 self.FTP_WEI = ftp_wei
937 self.FTP_WEI = ftp_wei
938 self.EXP_CODE = exp_code
938 self.EXP_CODE = exp_code
939 self.SUB_EXP_CODE = sub_exp_code
939 self.SUB_EXP_CODE = sub_exp_code
940 self.PLOT_POS = plot_pos
940 self.PLOT_POS = plot_pos
941
941
942 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
942 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
943 self.isConfig = True
943 self.isConfig = True
944 self.figfile = figfile
944 self.figfile = figfile
945 update_figfile = True
945 update_figfile = True
946
946
947 self.setWinTitle(title)
947 self.setWinTitle(title)
948
948
949 for i in range(self.nchan):
949 for i in range(self.nchan):
950 index = channelIndexList[i]
950 index = channelIndexList[i]
951 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
951 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
952 axes = self.axesList[i*self.plotFact]
952 axes = self.axesList[i*self.plotFact]
953 z1 = z[i,:].reshape((1,-1))
953 z1 = z[i,:].reshape((1,-1))
954 axes.pcolorbuffer(x, y, z1,
954 axes.pcolorbuffer(x, y, z1,
955 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
955 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
956 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
956 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
957 ticksize=9, cblabel='', cbsize="1%",colormap=colormap)
957 ticksize=9, cblabel='', cbsize="1%",colormap=colormap)
958
958
959 if showSNR:
959 if showSNR:
960 title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
960 title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
961 axes = self.axesList[i*self.plotFact + 1]
961 axes = self.axesList[i*self.plotFact + 1]
962 SNRdB1 = SNRdB[i,:].reshape((1,-1))
962 SNRdB1 = SNRdB[i,:].reshape((1,-1))
963 axes.pcolorbuffer(x, y, SNRdB1,
963 axes.pcolorbuffer(x, y, SNRdB1,
964 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
964 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
965 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
965 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
966 ticksize=9, cblabel='', cbsize="1%",colormap='jet')
966 ticksize=9, cblabel='', cbsize="1%",colormap='jet')
967
967
968
968
969 self.draw()
969 self.draw()
970
970
971 if dataOut.ltctime >= self.xmax:
971 if dataOut.ltctime >= self.xmax:
972 self.counter_imagwr = wr_period
972 self.counter_imagwr = wr_period
973 self.isConfig = False
973 self.isConfig = False
974 update_figfile = True
974 update_figfile = True
975
975
976 self.save(figpath=figpath,
976 self.save(figpath=figpath,
977 figfile=figfile,
977 figfile=figfile,
978 save=save,
978 save=save,
979 ftp=ftp,
979 ftp=ftp,
980 wr_period=wr_period,
980 wr_period=wr_period,
981 thisDatetime=thisDatetime,
981 thisDatetime=thisDatetime,
982 update_figfile=update_figfile)
982 update_figfile=update_figfile)
983
983
984
984
985
985
986 class Parameters1Plot(Figure):
986 class Parameters1Plot(Figure):
987
987
988 __isConfig = None
988 __isConfig = None
989 __nsubplots = None
989 __nsubplots = None
990
990
991 WIDTHPROF = None
991 WIDTHPROF = None
992 HEIGHTPROF = None
992 HEIGHTPROF = None
993 PREFIX = 'prm'
993 PREFIX = 'prm'
994
994
995 def __init__(self, **kwargs):
995 def __init__(self, **kwargs):
996 Figure.__init__(self, **kwargs)
996 Figure.__init__(self, **kwargs)
997 self.timerange = 2*60*60
997 self.timerange = 2*60*60
998 self.isConfig = False
998 self.isConfig = False
999 self.__nsubplots = 1
999 self.__nsubplots = 1
1000
1000
1001 self.WIDTH = 800
1001 self.WIDTH = 800
1002 self.HEIGHT = 180
1002 self.HEIGHT = 180
1003 self.WIDTHPROF = 120
1003 self.WIDTHPROF = 120
1004 self.HEIGHTPROF = 0
1004 self.HEIGHTPROF = 0
1005 self.counter_imagwr = 0
1005 self.counter_imagwr = 0
1006
1006
1007 self.PLOT_CODE = PARMS_CODE
1007 self.PLOT_CODE = PARMS_CODE
1008
1008
1009 self.FTP_WEI = None
1009 self.FTP_WEI = None
1010 self.EXP_CODE = None
1010 self.EXP_CODE = None
1011 self.SUB_EXP_CODE = None
1011 self.SUB_EXP_CODE = None
1012 self.PLOT_POS = None
1012 self.PLOT_POS = None
1013 self.tmin = None
1013 self.tmin = None
1014 self.tmax = None
1014 self.tmax = None
1015
1015
1016 self.xmin = None
1016 self.xmin = None
1017 self.xmax = None
1017 self.xmax = None
1018
1018
1019 self.figfile = None
1019 self.figfile = None
1020
1020
1021 def getSubplots(self):
1021 def getSubplots(self):
1022
1022
1023 ncol = 1
1023 ncol = 1
1024 nrow = self.nplots
1024 nrow = self.nplots
1025
1025
1026 return nrow, ncol
1026 return nrow, ncol
1027
1027
1028 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1028 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1029
1029
1030 self.__showprofile = showprofile
1030 self.__showprofile = showprofile
1031 self.nplots = nplots
1031 self.nplots = nplots
1032
1032
1033 ncolspan = 1
1033 ncolspan = 1
1034 colspan = 1
1034 colspan = 1
1035
1035
1036 self.createFigure(id = id,
1036 self.createFigure(id = id,
1037 wintitle = wintitle,
1037 wintitle = wintitle,
1038 widthplot = self.WIDTH + self.WIDTHPROF,
1038 widthplot = self.WIDTH + self.WIDTHPROF,
1039 heightplot = self.HEIGHT + self.HEIGHTPROF,
1039 heightplot = self.HEIGHT + self.HEIGHTPROF,
1040 show=show)
1040 show=show)
1041
1041
1042 nrow, ncol = self.getSubplots()
1042 nrow, ncol = self.getSubplots()
1043
1043
1044 counter = 0
1044 counter = 0
1045 for y in range(nrow):
1045 for y in range(nrow):
1046 for x in range(ncol):
1046 for x in range(ncol):
1047
1047
1048 if counter >= self.nplots:
1048 if counter >= self.nplots:
1049 break
1049 break
1050
1050
1051 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1051 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1052
1052
1053 if showprofile:
1053 if showprofile:
1054 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1054 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1055
1055
1056 counter += 1
1056 counter += 1
1057
1057
1058 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
1058 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
1059 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None,
1059 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None,
1060 parameterIndex = None, onlyPositive = False,
1060 parameterIndex = None, onlyPositive = False,
1061 SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False,
1061 SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False,
1062 DOP = True,
1062 DOP = True,
1063 zlabel = "", parameterName = "", parameterObject = "data_param",
1063 zlabel = "", parameterName = "", parameterObject = "data_param",
1064 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1064 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1065 server=None, folder=None, username=None, password=None,
1065 server=None, folder=None, username=None, password=None,
1066 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1066 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1067 #print inspect.getargspec(self.run).args
1067 #print inspect.getargspec(self.run).args
1068 """
1068 """
1069
1069
1070 Input:
1070 Input:
1071 dataOut :
1071 dataOut :
1072 id :
1072 id :
1073 wintitle :
1073 wintitle :
1074 channelList :
1074 channelList :
1075 showProfile :
1075 showProfile :
1076 xmin : None,
1076 xmin : None,
1077 xmax : None,
1077 xmax : None,
1078 ymin : None,
1078 ymin : None,
1079 ymax : None,
1079 ymax : None,
1080 zmin : None,
1080 zmin : None,
1081 zmax : None
1081 zmax : None
1082 """
1082 """
1083
1083
1084 data_param = getattr(dataOut, parameterObject)
1084 data_param = getattr(dataOut, parameterObject)
1085
1085
1086 if channelList == None:
1086 if channelList == None:
1087 channelIndexList = numpy.arange(data_param.shape[0])
1087 channelIndexList = numpy.arange(data_param.shape[0])
1088 else:
1088 else:
1089 channelIndexList = numpy.array(channelList)
1089 channelIndexList = numpy.array(channelList)
1090
1090
1091 nchan = len(channelIndexList) #Number of channels being plotted
1091 nchan = len(channelIndexList) #Number of channels being plotted
1092
1092
1093 if nchan < 1:
1093 if nchan < 1:
1094 return
1094 return
1095
1095
1096 nGraphsByChannel = 0
1096 nGraphsByChannel = 0
1097
1097
1098 if SNR:
1098 if SNR:
1099 nGraphsByChannel += 1
1099 nGraphsByChannel += 1
1100 if DOP:
1100 if DOP:
1101 nGraphsByChannel += 1
1101 nGraphsByChannel += 1
1102
1102
1103 if nGraphsByChannel < 1:
1103 if nGraphsByChannel < 1:
1104 return
1104 return
1105
1105
1106 nplots = nGraphsByChannel*nchan
1106 nplots = nGraphsByChannel*nchan
1107
1107
1108 if timerange is not None:
1108 if timerange is not None:
1109 self.timerange = timerange
1109 self.timerange = timerange
1110
1110
1111 #tmin = None
1111 #tmin = None
1112 #tmax = None
1112 #tmax = None
1113 if parameterIndex == None:
1113 if parameterIndex == None:
1114 parameterIndex = 1
1114 parameterIndex = 1
1115
1115
1116 x = dataOut.getTimeRange1(dataOut.paramInterval)
1116 x = dataOut.getTimeRange1(dataOut.paramInterval)
1117 y = dataOut.heightList
1117 y = dataOut.heightList
1118
1118
1119 if dataOut.data_param.ndim == 3:
1119 if dataOut.data_param.ndim == 3:
1120 z = dataOut.data_param[channelIndexList,parameterIndex,:]
1120 z = dataOut.data_param[channelIndexList,parameterIndex,:]
1121 else:
1121 else:
1122 z = dataOut.data_param[channelIndexList,:]
1122 z = dataOut.data_param[channelIndexList,:]
1123
1123
1124 if dataOut.data_SNR is not None:
1124 if dataOut.data_SNR is not None:
1125 if dataOut.data_SNR.ndim == 2:
1125 if dataOut.data_SNR.ndim == 2:
1126 SNRavg = numpy.average(dataOut.data_SNR, axis=0)
1126 SNRavg = numpy.average(dataOut.data_SNR, axis=0)
1127 else:
1127 else:
1128 SNRavg = dataOut.data_SNR
1128 SNRavg = dataOut.data_SNR
1129 SNRdB = 10*numpy.log10(SNRavg)
1129 SNRdB = 10*numpy.log10(SNRavg)
1130
1130
1131 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1131 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1132 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1132 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1133 xlabel = ""
1133 xlabel = ""
1134 ylabel = "Range (Km)"
1134 ylabel = "Range (Km)"
1135
1135
1136 if onlyPositive:
1136 if onlyPositive:
1137 colormap = "jet"
1137 colormap = "jet"
1138 zmin = 0
1138 zmin = 0
1139 else: colormap = "RdBu_r"
1139 else: colormap = "RdBu_r"
1140
1140
1141 if not self.isConfig:
1141 if not self.isConfig:
1142
1142
1143 self.setup(id=id,
1143 self.setup(id=id,
1144 nplots=nplots,
1144 nplots=nplots,
1145 wintitle=wintitle,
1145 wintitle=wintitle,
1146 showprofile=showprofile,
1146 showprofile=showprofile,
1147 show=show)
1147 show=show)
1148
1148
1149 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1149 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1150
1150
1151 if ymin == None: ymin = numpy.nanmin(y)
1151 if ymin == None: ymin = numpy.nanmin(y)
1152 if ymax == None: ymax = numpy.nanmax(y)
1152 if ymax == None: ymax = numpy.nanmax(y)
1153 if zmin == None: zmin = numpy.nanmin(z)
1153 if zmin == None: zmin = numpy.nanmin(z)
1154 if zmax == None: zmax = numpy.nanmax(z)
1154 if zmax == None: zmax = numpy.nanmax(z)
1155
1155
1156 if SNR:
1156 if SNR:
1157 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
1157 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
1158 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
1158 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
1159
1159
1160 self.FTP_WEI = ftp_wei
1160 self.FTP_WEI = ftp_wei
1161 self.EXP_CODE = exp_code
1161 self.EXP_CODE = exp_code
1162 self.SUB_EXP_CODE = sub_exp_code
1162 self.SUB_EXP_CODE = sub_exp_code
1163 self.PLOT_POS = plot_pos
1163 self.PLOT_POS = plot_pos
1164
1164
1165 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1165 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1166 self.isConfig = True
1166 self.isConfig = True
1167 self.figfile = figfile
1167 self.figfile = figfile
1168
1168
1169 self.setWinTitle(title)
1169 self.setWinTitle(title)
1170
1170
1171 if ((self.xmax - x[1]) < (x[1]-x[0])):
1171 if ((self.xmax - x[1]) < (x[1]-x[0])):
1172 x[1] = self.xmax
1172 x[1] = self.xmax
1173
1173
1174 for i in range(nchan):
1174 for i in range(nchan):
1175
1175
1176 if (SNR and not onlySNR): j = 2*i
1176 if (SNR and not onlySNR): j = 2*i
1177 else: j = i
1177 else: j = i
1178
1178
1179 j = nGraphsByChannel*i
1179 j = nGraphsByChannel*i
1180
1180
1181 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1181 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1182 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
1182 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
1183
1183
1184 if not onlySNR:
1184 if not onlySNR:
1185 axes = self.axesList[j*self.__nsubplots]
1185 axes = self.axesList[j*self.__nsubplots]
1186 z1 = z[i,:].reshape((1,-1))
1186 z1 = z[i,:].reshape((1,-1))
1187 axes.pcolorbuffer(x, y, z1,
1187 axes.pcolorbuffer(x, y, z1,
1188 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1188 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1189 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
1189 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
1190 ticksize=9, cblabel=zlabel, cbsize="1%")
1190 ticksize=9, cblabel=zlabel, cbsize="1%")
1191
1191
1192 if DOP:
1192 if DOP:
1193 title = "%s Channel %d: %s" %(parameterName, channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1193 title = "%s Channel %d: %s" %(parameterName, channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1194
1194
1195 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1195 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1196 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
1196 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
1197 axes = self.axesList[j]
1197 axes = self.axesList[j]
1198 z1 = z[i,:].reshape((1,-1))
1198 z1 = z[i,:].reshape((1,-1))
1199 axes.pcolorbuffer(x, y, z1,
1199 axes.pcolorbuffer(x, y, z1,
1200 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1200 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1201 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
1201 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
1202 ticksize=9, cblabel=zlabel, cbsize="1%")
1202 ticksize=9, cblabel=zlabel, cbsize="1%")
1203
1203
1204 if SNR:
1204 if SNR:
1205 title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1205 title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1206 axes = self.axesList[(j)*self.__nsubplots]
1206 axes = self.axesList[(j)*self.__nsubplots]
1207 if not onlySNR:
1207 if not onlySNR:
1208 axes = self.axesList[(j + 1)*self.__nsubplots]
1208 axes = self.axesList[(j + 1)*self.__nsubplots]
1209
1209
1210 axes = self.axesList[(j + nGraphsByChannel-1)]
1210 axes = self.axesList[(j + nGraphsByChannel-1)]
1211 z1 = SNRdB.reshape((1,-1))
1211 z1 = SNRdB.reshape((1,-1))
1212 axes.pcolorbuffer(x, y, z1,
1212 axes.pcolorbuffer(x, y, z1,
1213 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1213 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1214 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet",
1214 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet",
1215 ticksize=9, cblabel=zlabel, cbsize="1%")
1215 ticksize=9, cblabel=zlabel, cbsize="1%")
1216
1216
1217
1217
1218
1218
1219 self.draw()
1219 self.draw()
1220
1220
1221 if x[1] >= self.axesList[0].xmax:
1221 if x[1] >= self.axesList[0].xmax:
1222 self.counter_imagwr = wr_period
1222 self.counter_imagwr = wr_period
1223 self.isConfig = False
1223 self.isConfig = False
1224 self.figfile = None
1224 self.figfile = None
1225
1225
1226 self.save(figpath=figpath,
1226 self.save(figpath=figpath,
1227 figfile=figfile,
1227 figfile=figfile,
1228 save=save,
1228 save=save,
1229 ftp=ftp,
1229 ftp=ftp,
1230 wr_period=wr_period,
1230 wr_period=wr_period,
1231 thisDatetime=thisDatetime,
1231 thisDatetime=thisDatetime,
1232 update_figfile=False)
1232 update_figfile=False)
1233
1233
1234 class SpectralFittingPlot(Figure):
1234 class SpectralFittingPlot(Figure):
1235
1235
1236 __isConfig = None
1236 __isConfig = None
1237 __nsubplots = None
1237 __nsubplots = None
1238
1238
1239 WIDTHPROF = None
1239 WIDTHPROF = None
1240 HEIGHTPROF = None
1240 HEIGHTPROF = None
1241 PREFIX = 'prm'
1241 PREFIX = 'prm'
1242
1242
1243
1243
1244 N = None
1244 N = None
1245 ippSeconds = None
1245 ippSeconds = None
1246
1246
1247 def __init__(self, **kwargs):
1247 def __init__(self, **kwargs):
1248 Figure.__init__(self, **kwargs)
1248 Figure.__init__(self, **kwargs)
1249 self.isConfig = False
1249 self.isConfig = False
1250 self.__nsubplots = 1
1250 self.__nsubplots = 1
1251
1251
1252 self.PLOT_CODE = SPECFIT_CODE
1252 self.PLOT_CODE = SPECFIT_CODE
1253
1253
1254 self.WIDTH = 450
1254 self.WIDTH = 450
1255 self.HEIGHT = 250
1255 self.HEIGHT = 250
1256 self.WIDTHPROF = 0
1256 self.WIDTHPROF = 0
1257 self.HEIGHTPROF = 0
1257 self.HEIGHTPROF = 0
1258
1258
1259 def getSubplots(self):
1259 def getSubplots(self):
1260
1260
1261 ncol = int(numpy.sqrt(self.nplots)+0.9)
1261 ncol = int(numpy.sqrt(self.nplots)+0.9)
1262 nrow = int(self.nplots*1./ncol + 0.9)
1262 nrow = int(self.nplots*1./ncol + 0.9)
1263
1263
1264 return nrow, ncol
1264 return nrow, ncol
1265
1265
1266 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
1266 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
1267
1267
1268 showprofile = False
1268 showprofile = False
1269 self.__showprofile = showprofile
1269 self.__showprofile = showprofile
1270 self.nplots = nplots
1270 self.nplots = nplots
1271
1271
1272 ncolspan = 5
1272 ncolspan = 5
1273 colspan = 4
1273 colspan = 4
1274 if showprofile:
1274 if showprofile:
1275 ncolspan = 5
1275 ncolspan = 5
1276 colspan = 4
1276 colspan = 4
1277 self.__nsubplots = 2
1277 self.__nsubplots = 2
1278
1278
1279 self.createFigure(id = id,
1279 self.createFigure(id = id,
1280 wintitle = wintitle,
1280 wintitle = wintitle,
1281 widthplot = self.WIDTH + self.WIDTHPROF,
1281 widthplot = self.WIDTH + self.WIDTHPROF,
1282 heightplot = self.HEIGHT + self.HEIGHTPROF,
1282 heightplot = self.HEIGHT + self.HEIGHTPROF,
1283 show=show)
1283 show=show)
1284
1284
1285 nrow, ncol = self.getSubplots()
1285 nrow, ncol = self.getSubplots()
1286
1286
1287 counter = 0
1287 counter = 0
1288 for y in range(nrow):
1288 for y in range(nrow):
1289 for x in range(ncol):
1289 for x in range(ncol):
1290
1290
1291 if counter >= self.nplots:
1291 if counter >= self.nplots:
1292 break
1292 break
1293
1293
1294 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1294 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1295
1295
1296 if showprofile:
1296 if showprofile:
1297 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1297 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1298
1298
1299 counter += 1
1299 counter += 1
1300
1300
1301 def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True,
1301 def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True,
1302 xmin=None, xmax=None, ymin=None, ymax=None,
1302 xmin=None, xmax=None, ymin=None, ymax=None,
1303 save=False, figpath='./', figfile=None, show=True):
1303 save=False, figpath='./', figfile=None, show=True):
1304
1304
1305 """
1305 """
1306
1306
1307 Input:
1307 Input:
1308 dataOut :
1308 dataOut :
1309 id :
1309 id :
1310 wintitle :
1310 wintitle :
1311 channelList :
1311 channelList :
1312 showProfile :
1312 showProfile :
1313 xmin : None,
1313 xmin : None,
1314 xmax : None,
1314 xmax : None,
1315 zmin : None,
1315 zmin : None,
1316 zmax : None
1316 zmax : None
1317 """
1317 """
1318
1318
1319 if cutHeight==None:
1319 if cutHeight==None:
1320 h=270
1320 h=270
1321 heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin()
1321 heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin()
1322 cutHeight = dataOut.heightList[heightindex]
1322 cutHeight = dataOut.heightList[heightindex]
1323
1323
1324 factor = dataOut.normFactor
1324 factor = dataOut.normFactor
1325 x = dataOut.abscissaList[:-1]
1325 x = dataOut.abscissaList[:-1]
1326 #y = dataOut.getHeiRange()
1326 #y = dataOut.getHeiRange()
1327
1327
1328 z = dataOut.data_pre[:,:,heightindex]/factor
1328 z = dataOut.data_pre[:,:,heightindex]/factor
1329 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1329 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1330 avg = numpy.average(z, axis=1)
1330 avg = numpy.average(z, axis=1)
1331 listChannels = z.shape[0]
1331 listChannels = z.shape[0]
1332
1332
1333 #Reconstruct Function
1333 #Reconstruct Function
1334 if fit==True:
1334 if fit==True:
1335 groupArray = dataOut.groupList
1335 groupArray = dataOut.groupList
1336 listChannels = groupArray.reshape((groupArray.size))
1336 listChannels = groupArray.reshape((groupArray.size))
1337 listChannels.sort()
1337 listChannels.sort()
1338 spcFitLine = numpy.zeros(z.shape)
1338 spcFitLine = numpy.zeros(z.shape)
1339 constants = dataOut.constants
1339 constants = dataOut.constants
1340
1340
1341 nGroups = groupArray.shape[0]
1341 nGroups = groupArray.shape[0]
1342 nChannels = groupArray.shape[1]
1342 nChannels = groupArray.shape[1]
1343 nProfiles = z.shape[1]
1343 nProfiles = z.shape[1]
1344
1344
1345 for f in range(nGroups):
1345 for f in range(nGroups):
1346 groupChann = groupArray[f,:]
1346 groupChann = groupArray[f,:]
1347 p = dataOut.data_param[f,:,heightindex]
1347 p = dataOut.data_param[f,:,heightindex]
1348 # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167])
1348 # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167])
1349 fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles
1349 fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles
1350 fitLineAux = fitLineAux.reshape((nChannels,nProfiles))
1350 fitLineAux = fitLineAux.reshape((nChannels,nProfiles))
1351 spcFitLine[groupChann,:] = fitLineAux
1351 spcFitLine[groupChann,:] = fitLineAux
1352 # spcFitLine = spcFitLine/factor
1352 # spcFitLine = spcFitLine/factor
1353
1353
1354 z = z[listChannels,:]
1354 z = z[listChannels,:]
1355 spcFitLine = spcFitLine[listChannels,:]
1355 spcFitLine = spcFitLine[listChannels,:]
1356 spcFitLinedB = 10*numpy.log10(spcFitLine)
1356 spcFitLinedB = 10*numpy.log10(spcFitLine)
1357
1357
1358 zdB = 10*numpy.log10(z)
1358 zdB = 10*numpy.log10(z)
1359 #thisDatetime = dataOut.datatime
1359 #thisDatetime = dataOut.datatime
1360 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1360 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1361 title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1361 title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1362 xlabel = "Velocity (m/s)"
1362 xlabel = "Velocity (m/s)"
1363 ylabel = "Spectrum"
1363 ylabel = "Spectrum"
1364
1364
1365 if not self.isConfig:
1365 if not self.isConfig:
1366
1366
1367 nplots = listChannels.size
1367 nplots = listChannels.size
1368
1368
1369 self.setup(id=id,
1369 self.setup(id=id,
1370 nplots=nplots,
1370 nplots=nplots,
1371 wintitle=wintitle,
1371 wintitle=wintitle,
1372 showprofile=showprofile,
1372 showprofile=showprofile,
1373 show=show)
1373 show=show)
1374
1374
1375 if xmin == None: xmin = numpy.nanmin(x)
1375 if xmin == None: xmin = numpy.nanmin(x)
1376 if xmax == None: xmax = numpy.nanmax(x)
1376 if xmax == None: xmax = numpy.nanmax(x)
1377 if ymin == None: ymin = numpy.nanmin(zdB)
1377 if ymin == None: ymin = numpy.nanmin(zdB)
1378 if ymax == None: ymax = numpy.nanmax(zdB)+2
1378 if ymax == None: ymax = numpy.nanmax(zdB)+2
1379
1379
1380 self.isConfig = True
1380 self.isConfig = True
1381
1381
1382 self.setWinTitle(title)
1382 self.setWinTitle(title)
1383 for i in range(self.nplots):
1383 for i in range(self.nplots):
1384 # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i])
1384 # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i])
1385 title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i])
1385 title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i])
1386 axes = self.axesList[i*self.__nsubplots]
1386 axes = self.axesList[i*self.__nsubplots]
1387 if fit == False:
1387 if fit == False:
1388 axes.pline(x, zdB[i,:],
1388 axes.pline(x, zdB[i,:],
1389 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1389 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1390 xlabel=xlabel, ylabel=ylabel, title=title
1390 xlabel=xlabel, ylabel=ylabel, title=title
1391 )
1391 )
1392 if fit == True:
1392 if fit == True:
1393 fitline=spcFitLinedB[i,:]
1393 fitline=spcFitLinedB[i,:]
1394 y=numpy.vstack([zdB[i,:],fitline] )
1394 y=numpy.vstack([zdB[i,:],fitline] )
1395 legendlabels=['Data','Fitting']
1395 legendlabels=['Data','Fitting']
1396 axes.pmultilineyaxis(x, y,
1396 axes.pmultilineyaxis(x, y,
1397 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1397 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1398 xlabel=xlabel, ylabel=ylabel, title=title,
1398 xlabel=xlabel, ylabel=ylabel, title=title,
1399 legendlabels=legendlabels, marker=None,
1399 legendlabels=legendlabels, marker=None,
1400 linestyle='solid', grid='both')
1400 linestyle='solid', grid='both')
1401
1401
1402 self.draw()
1402 self.draw()
1403
1403
1404 self.save(figpath=figpath,
1404 self.save(figpath=figpath,
1405 figfile=figfile,
1405 figfile=figfile,
1406 save=save,
1406 save=save,
1407 ftp=ftp,
1407 ftp=ftp,
1408 wr_period=wr_period,
1408 wr_period=wr_period,
1409 thisDatetime=thisDatetime)
1409 thisDatetime=thisDatetime)
1410
1410
1411
1411
1412 class EWDriftsPlot(Figure):
1412 class EWDriftsPlot(Figure):
1413
1413
1414 __isConfig = None
1414 __isConfig = None
1415 __nsubplots = None
1415 __nsubplots = None
1416
1416
1417 WIDTHPROF = None
1417 WIDTHPROF = None
1418 HEIGHTPROF = None
1418 HEIGHTPROF = None
1419 PREFIX = 'drift'
1419 PREFIX = 'drift'
1420
1420
1421 def __init__(self, **kwargs):
1421 def __init__(self, **kwargs):
1422 Figure.__init__(self, **kwargs)
1422 Figure.__init__(self, **kwargs)
1423 self.timerange = 2*60*60
1423 self.timerange = 2*60*60
1424 self.isConfig = False
1424 self.isConfig = False
1425 self.__nsubplots = 1
1425 self.__nsubplots = 1
1426
1426
1427 self.WIDTH = 800
1427 self.WIDTH = 800
1428 self.HEIGHT = 150
1428 self.HEIGHT = 150
1429 self.WIDTHPROF = 120
1429 self.WIDTHPROF = 120
1430 self.HEIGHTPROF = 0
1430 self.HEIGHTPROF = 0
1431 self.counter_imagwr = 0
1431 self.counter_imagwr = 0
1432
1432
1433 self.PLOT_CODE = EWDRIFT_CODE
1433 self.PLOT_CODE = EWDRIFT_CODE
1434
1434
1435 self.FTP_WEI = None
1435 self.FTP_WEI = None
1436 self.EXP_CODE = None
1436 self.EXP_CODE = None
1437 self.SUB_EXP_CODE = None
1437 self.SUB_EXP_CODE = None
1438 self.PLOT_POS = None
1438 self.PLOT_POS = None
1439 self.tmin = None
1439 self.tmin = None
1440 self.tmax = None
1440 self.tmax = None
1441
1441
1442 self.xmin = None
1442 self.xmin = None
1443 self.xmax = None
1443 self.xmax = None
1444
1444
1445 self.figfile = None
1445 self.figfile = None
1446
1446
1447 def getSubplots(self):
1447 def getSubplots(self):
1448
1448
1449 ncol = 1
1449 ncol = 1
1450 nrow = self.nplots
1450 nrow = self.nplots
1451
1451
1452 return nrow, ncol
1452 return nrow, ncol
1453
1453
1454 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1454 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1455
1455
1456 self.__showprofile = showprofile
1456 self.__showprofile = showprofile
1457 self.nplots = nplots
1457 self.nplots = nplots
1458
1458
1459 ncolspan = 1
1459 ncolspan = 1
1460 colspan = 1
1460 colspan = 1
1461
1461
1462 self.createFigure(id = id,
1462 self.createFigure(id = id,
1463 wintitle = wintitle,
1463 wintitle = wintitle,
1464 widthplot = self.WIDTH + self.WIDTHPROF,
1464 widthplot = self.WIDTH + self.WIDTHPROF,
1465 heightplot = self.HEIGHT + self.HEIGHTPROF,
1465 heightplot = self.HEIGHT + self.HEIGHTPROF,
1466 show=show)
1466 show=show)
1467
1467
1468 nrow, ncol = self.getSubplots()
1468 nrow, ncol = self.getSubplots()
1469
1469
1470 counter = 0
1470 counter = 0
1471 for y in range(nrow):
1471 for y in range(nrow):
1472 if counter >= self.nplots:
1472 if counter >= self.nplots:
1473 break
1473 break
1474
1474
1475 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
1475 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
1476 counter += 1
1476 counter += 1
1477
1477
1478 def run(self, dataOut, id, wintitle="", channelList=None,
1478 def run(self, dataOut, id, wintitle="", channelList=None,
1479 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
1479 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
1480 zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None,
1480 zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None,
1481 timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False,
1481 timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False,
1482 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1482 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1483 server=None, folder=None, username=None, password=None,
1483 server=None, folder=None, username=None, password=None,
1484 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1484 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1485 """
1485 """
1486
1486
1487 Input:
1487 Input:
1488 dataOut :
1488 dataOut :
1489 id :
1489 id :
1490 wintitle :
1490 wintitle :
1491 channelList :
1491 channelList :
1492 showProfile :
1492 showProfile :
1493 xmin : None,
1493 xmin : None,
1494 xmax : None,
1494 xmax : None,
1495 ymin : None,
1495 ymin : None,
1496 ymax : None,
1496 ymax : None,
1497 zmin : None,
1497 zmin : None,
1498 zmax : None
1498 zmax : None
1499 """
1499 """
1500
1500
1501 if timerange is not None:
1501 if timerange is not None:
1502 self.timerange = timerange
1502 self.timerange = timerange
1503
1503
1504 tmin = None
1504 tmin = None
1505 tmax = None
1505 tmax = None
1506
1506
1507 x = dataOut.getTimeRange1(dataOut.outputInterval)
1507 x = dataOut.getTimeRange1(dataOut.outputInterval)
1508 # y = dataOut.heightList
1508 # y = dataOut.heightList
1509 y = dataOut.heightList
1509 y = dataOut.heightList
1510
1510
1511 z = dataOut.data_output
1511 z = dataOut.data_output
1512 nplots = z.shape[0] #Number of wind dimensions estimated
1512 nplots = z.shape[0] #Number of wind dimensions estimated
1513 nplotsw = nplots
1513 nplotsw = nplots
1514
1514
1515 #If there is a SNR function defined
1515 #If there is a SNR function defined
1516 if dataOut.data_SNR is not None:
1516 if dataOut.data_SNR is not None:
1517 nplots += 1
1517 nplots += 1
1518 SNR = dataOut.data_SNR
1518 SNR = dataOut.data_SNR
1519
1519
1520 if SNR_1:
1520 if SNR_1:
1521 SNR += 1
1521 SNR += 1
1522
1522
1523 SNRavg = numpy.average(SNR, axis=0)
1523 SNRavg = numpy.average(SNR, axis=0)
1524
1524
1525 SNRdB = 10*numpy.log10(SNR)
1525 SNRdB = 10*numpy.log10(SNR)
1526 SNRavgdB = 10*numpy.log10(SNRavg)
1526 SNRavgdB = 10*numpy.log10(SNRavg)
1527
1527
1528 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
1528 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
1529
1529
1530 for i in range(nplotsw):
1530 for i in range(nplotsw):
1531 z[i,ind] = numpy.nan
1531 z[i,ind] = numpy.nan
1532
1532
1533
1533
1534 showprofile = False
1534 showprofile = False
1535 # thisDatetime = dataOut.datatime
1535 # thisDatetime = dataOut.datatime
1536 thisDatetime = datetime.datetime.utcfromtimestamp(x[1])
1536 thisDatetime = datetime.datetime.utcfromtimestamp(x[1])
1537 title = wintitle + " EW Drifts"
1537 title = wintitle + " EW Drifts"
1538 xlabel = ""
1538 xlabel = ""
1539 ylabel = "Height (Km)"
1539 ylabel = "Height (Km)"
1540
1540
1541 if not self.isConfig:
1541 if not self.isConfig:
1542
1542
1543 self.setup(id=id,
1543 self.setup(id=id,
1544 nplots=nplots,
1544 nplots=nplots,
1545 wintitle=wintitle,
1545 wintitle=wintitle,
1546 showprofile=showprofile,
1546 showprofile=showprofile,
1547 show=show)
1547 show=show)
1548
1548
1549 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1549 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1550
1550
1551 if ymin == None: ymin = numpy.nanmin(y)
1551 if ymin == None: ymin = numpy.nanmin(y)
1552 if ymax == None: ymax = numpy.nanmax(y)
1552 if ymax == None: ymax = numpy.nanmax(y)
1553
1553
1554 if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:]))
1554 if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:]))
1555 if zminZonal == None: zminZonal = -zmaxZonal
1555 if zminZonal == None: zminZonal = -zmaxZonal
1556 if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:]))
1556 if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:]))
1557 if zminVertical == None: zminVertical = -zmaxVertical
1557 if zminVertical == None: zminVertical = -zmaxVertical
1558
1558
1559 if dataOut.data_SNR is not None:
1559 if dataOut.data_SNR is not None:
1560 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
1560 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
1561 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
1561 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
1562
1562
1563 self.FTP_WEI = ftp_wei
1563 self.FTP_WEI = ftp_wei
1564 self.EXP_CODE = exp_code
1564 self.EXP_CODE = exp_code
1565 self.SUB_EXP_CODE = sub_exp_code
1565 self.SUB_EXP_CODE = sub_exp_code
1566 self.PLOT_POS = plot_pos
1566 self.PLOT_POS = plot_pos
1567
1567
1568 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1568 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1569 self.isConfig = True
1569 self.isConfig = True
1570
1570
1571
1571
1572 self.setWinTitle(title)
1572 self.setWinTitle(title)
1573
1573
1574 if ((self.xmax - x[1]) < (x[1]-x[0])):
1574 if ((self.xmax - x[1]) < (x[1]-x[0])):
1575 x[1] = self.xmax
1575 x[1] = self.xmax
1576
1576
1577 strWind = ['Zonal','Vertical']
1577 strWind = ['Zonal','Vertical']
1578 strCb = 'Velocity (m/s)'
1578 strCb = 'Velocity (m/s)'
1579 zmaxVector = [zmaxZonal, zmaxVertical]
1579 zmaxVector = [zmaxZonal, zmaxVertical]
1580 zminVector = [zminZonal, zminVertical]
1580 zminVector = [zminZonal, zminVertical]
1581
1581
1582 for i in range(nplotsw):
1582 for i in range(nplotsw):
1583
1583
1584 title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1584 title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1585 axes = self.axesList[i*self.__nsubplots]
1585 axes = self.axesList[i*self.__nsubplots]
1586
1586
1587 z1 = z[i,:].reshape((1,-1))
1587 z1 = z[i,:].reshape((1,-1))
1588
1588
1589 axes.pcolorbuffer(x, y, z1,
1589 axes.pcolorbuffer(x, y, z1,
1590 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
1590 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
1591 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1591 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1592 ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r")
1592 ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r")
1593
1593
1594 if dataOut.data_SNR is not None:
1594 if dataOut.data_SNR is not None:
1595 i += 1
1595 i += 1
1596 if SNR_1:
1596 if SNR_1:
1597 title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1597 title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1598 else:
1598 else:
1599 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1599 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1600 axes = self.axesList[i*self.__nsubplots]
1600 axes = self.axesList[i*self.__nsubplots]
1601 SNRavgdB = SNRavgdB.reshape((1,-1))
1601 SNRavgdB = SNRavgdB.reshape((1,-1))
1602
1602
1603 axes.pcolorbuffer(x, y, SNRavgdB,
1603 axes.pcolorbuffer(x, y, SNRavgdB,
1604 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1604 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1605 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1605 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1606 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
1606 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
1607
1607
1608 self.draw()
1608 self.draw()
1609
1609
1610 if x[1] >= self.axesList[0].xmax:
1610 if x[1] >= self.axesList[0].xmax:
1611 self.counter_imagwr = wr_period
1611 self.counter_imagwr = wr_period
1612 self.isConfig = False
1612 self.isConfig = False
1613 self.figfile = None
1613 self.figfile = None
1614
1614
1615
1615
1616
1616
1617
1617
1618 class PhasePlot(Figure):
1618 class PhasePlot(Figure):
1619
1619
1620 __isConfig = None
1620 __isConfig = None
1621 __nsubplots = None
1621 __nsubplots = None
1622
1622
1623 PREFIX = 'mphase'
1623 PREFIX = 'mphase'
1624
1624
1625
1625
1626 def __init__(self, **kwargs):
1626 def __init__(self, **kwargs):
1627 Figure.__init__(self, **kwargs)
1627 Figure.__init__(self, **kwargs)
1628 self.timerange = 24*60*60
1628 self.timerange = 24*60*60
1629 self.isConfig = False
1629 self.isConfig = False
1630 self.__nsubplots = 1
1630 self.__nsubplots = 1
1631 self.counter_imagwr = 0
1631 self.counter_imagwr = 0
1632 self.WIDTH = 600
1632 self.WIDTH = 600
1633 self.HEIGHT = 300
1633 self.HEIGHT = 300
1634 self.WIDTHPROF = 120
1634 self.WIDTHPROF = 120
1635 self.HEIGHTPROF = 0
1635 self.HEIGHTPROF = 0
1636 self.xdata = None
1636 self.xdata = None
1637 self.ydata = None
1637 self.ydata = None
1638
1638
1639 self.PLOT_CODE = MPHASE_CODE
1639 self.PLOT_CODE = MPHASE_CODE
1640
1640
1641 self.FTP_WEI = None
1641 self.FTP_WEI = None
1642 self.EXP_CODE = None
1642 self.EXP_CODE = None
1643 self.SUB_EXP_CODE = None
1643 self.SUB_EXP_CODE = None
1644 self.PLOT_POS = None
1644 self.PLOT_POS = None
1645
1645
1646
1646
1647 self.filename_phase = None
1647 self.filename_phase = None
1648
1648
1649 self.figfile = None
1649 self.figfile = None
1650
1650
1651 def getSubplots(self):
1651 def getSubplots(self):
1652
1652
1653 ncol = 1
1653 ncol = 1
1654 nrow = 1
1654 nrow = 1
1655
1655
1656 return nrow, ncol
1656 return nrow, ncol
1657
1657
1658 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1658 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1659
1659
1660 self.__showprofile = showprofile
1660 self.__showprofile = showprofile
1661 self.nplots = nplots
1661 self.nplots = nplots
1662
1662
1663 ncolspan = 7
1663 ncolspan = 7
1664 colspan = 6
1664 colspan = 6
1665 self.__nsubplots = 2
1665 self.__nsubplots = 2
1666
1666
1667 self.createFigure(id = id,
1667 self.createFigure(id = id,
1668 wintitle = wintitle,
1668 wintitle = wintitle,
1669 widthplot = self.WIDTH+self.WIDTHPROF,
1669 widthplot = self.WIDTH+self.WIDTHPROF,
1670 heightplot = self.HEIGHT+self.HEIGHTPROF,
1670 heightplot = self.HEIGHT+self.HEIGHTPROF,
1671 show=show)
1671 show=show)
1672
1672
1673 nrow, ncol = self.getSubplots()
1673 nrow, ncol = self.getSubplots()
1674
1674
1675 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1675 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1676
1676
1677
1677
1678 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1678 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1679 xmin=None, xmax=None, ymin=None, ymax=None,
1679 xmin=None, xmax=None, ymin=None, ymax=None,
1680 timerange=None,
1680 timerange=None,
1681 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1681 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1682 server=None, folder=None, username=None, password=None,
1682 server=None, folder=None, username=None, password=None,
1683 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1683 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1684
1684
1685
1685
1686 tmin = None
1686 tmin = None
1687 tmax = None
1687 tmax = None
1688 x = dataOut.getTimeRange1(dataOut.outputInterval)
1688 x = dataOut.getTimeRange1(dataOut.outputInterval)
1689 y = dataOut.getHeiRange()
1689 y = dataOut.getHeiRange()
1690
1690
1691
1691
1692 #thisDatetime = dataOut.datatime
1692 #thisDatetime = dataOut.datatime
1693 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1693 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1694 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1694 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1695 xlabel = "Local Time"
1695 xlabel = "Local Time"
1696 ylabel = "Phase"
1696 ylabel = "Phase"
1697
1697
1698
1698
1699 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1699 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1700 phase_beacon = dataOut.data_output
1700 phase_beacon = dataOut.data_output
1701 update_figfile = False
1701 update_figfile = False
1702
1702
1703 if not self.isConfig:
1703 if not self.isConfig:
1704
1704
1705 self.nplots = phase_beacon.size
1705 self.nplots = phase_beacon.size
1706
1706
1707 self.setup(id=id,
1707 self.setup(id=id,
1708 nplots=self.nplots,
1708 nplots=self.nplots,
1709 wintitle=wintitle,
1709 wintitle=wintitle,
1710 showprofile=showprofile,
1710 showprofile=showprofile,
1711 show=show)
1711 show=show)
1712
1712
1713 if timerange is not None:
1713 if timerange is not None:
1714 self.timerange = timerange
1714 self.timerange = timerange
1715
1715
1716 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1716 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1717
1717
1718 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1718 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1719 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1719 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1720
1720
1721 self.FTP_WEI = ftp_wei
1721 self.FTP_WEI = ftp_wei
1722 self.EXP_CODE = exp_code
1722 self.EXP_CODE = exp_code
1723 self.SUB_EXP_CODE = sub_exp_code
1723 self.SUB_EXP_CODE = sub_exp_code
1724 self.PLOT_POS = plot_pos
1724 self.PLOT_POS = plot_pos
1725
1725
1726 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1726 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1727 self.isConfig = True
1727 self.isConfig = True
1728 self.figfile = figfile
1728 self.figfile = figfile
1729 self.xdata = numpy.array([])
1729 self.xdata = numpy.array([])
1730 self.ydata = numpy.array([])
1730 self.ydata = numpy.array([])
1731
1731
1732 #open file beacon phase
1732 #open file beacon phase
1733 path = '%s%03d' %(self.PREFIX, self.id)
1733 path = '%s%03d' %(self.PREFIX, self.id)
1734 beacon_file = os.path.join(path,'%s.txt'%self.name)
1734 beacon_file = os.path.join(path,'%s.txt'%self.name)
1735 self.filename_phase = os.path.join(figpath,beacon_file)
1735 self.filename_phase = os.path.join(figpath,beacon_file)
1736 update_figfile = True
1736 update_figfile = True
1737
1737
1738
1738
1739 #store data beacon phase
1739 #store data beacon phase
1740 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1740 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1741
1741
1742 self.setWinTitle(title)
1742 self.setWinTitle(title)
1743
1743
1744
1744
1745 title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1745 title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1746
1746
1747 legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)]
1747 legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)]
1748
1748
1749 axes = self.axesList[0]
1749 axes = self.axesList[0]
1750
1750
1751 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1751 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1752
1752
1753 if len(self.ydata)==0:
1753 if len(self.ydata)==0:
1754 self.ydata = phase_beacon.reshape(-1,1)
1754 self.ydata = phase_beacon.reshape(-1,1)
1755 else:
1755 else:
1756 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1756 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1757
1757
1758
1758
1759 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1759 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1760 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1760 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1761 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1761 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1762 XAxisAsTime=True, grid='both'
1762 XAxisAsTime=True, grid='both'
1763 )
1763 )
1764
1764
1765 self.draw()
1765 self.draw()
1766
1766
1767 self.save(figpath=figpath,
1767 self.save(figpath=figpath,
1768 figfile=figfile,
1768 figfile=figfile,
1769 save=save,
1769 save=save,
1770 ftp=ftp,
1770 ftp=ftp,
1771 wr_period=wr_period,
1771 wr_period=wr_period,
1772 thisDatetime=thisDatetime,
1772 thisDatetime=thisDatetime,
1773 update_figfile=update_figfile)
1773 update_figfile=update_figfile)
1774
1774
1775 if dataOut.ltctime + dataOut.outputInterval >= self.xmax:
1775 if dataOut.ltctime + dataOut.outputInterval >= self.xmax:
1776 self.counter_imagwr = wr_period
1776 self.counter_imagwr = wr_period
1777 self.isConfig = False
1777 self.isConfig = False
1778 update_figfile = True
1778 update_figfile = True
1779
1779
1780
1780
1781
1781
1782 class NSMeteorDetection1Plot(Figure):
1782 class NSMeteorDetection1Plot(Figure):
1783
1783
1784 isConfig = None
1784 isConfig = None
1785 __nsubplots = None
1785 __nsubplots = None
1786
1786
1787 WIDTHPROF = None
1787 WIDTHPROF = None
1788 HEIGHTPROF = None
1788 HEIGHTPROF = None
1789 PREFIX = 'nsm'
1789 PREFIX = 'nsm'
1790
1790
1791 zminList = None
1791 zminList = None
1792 zmaxList = None
1792 zmaxList = None
1793 cmapList = None
1793 cmapList = None
1794 titleList = None
1794 titleList = None
1795 nPairs = None
1795 nPairs = None
1796 nChannels = None
1796 nChannels = None
1797 nParam = None
1797 nParam = None
1798
1798
1799 def __init__(self, **kwargs):
1799 def __init__(self, **kwargs):
1800 Figure.__init__(self, **kwargs)
1800 Figure.__init__(self, **kwargs)
1801 self.isConfig = False
1801 self.isConfig = False
1802 self.__nsubplots = 1
1802 self.__nsubplots = 1
1803
1803
1804 self.WIDTH = 750
1804 self.WIDTH = 750
1805 self.HEIGHT = 250
1805 self.HEIGHT = 250
1806 self.WIDTHPROF = 120
1806 self.WIDTHPROF = 120
1807 self.HEIGHTPROF = 0
1807 self.HEIGHTPROF = 0
1808 self.counter_imagwr = 0
1808 self.counter_imagwr = 0
1809
1809
1810 self.PLOT_CODE = SPEC_CODE
1810 self.PLOT_CODE = SPEC_CODE
1811
1811
1812 self.FTP_WEI = None
1812 self.FTP_WEI = None
1813 self.EXP_CODE = None
1813 self.EXP_CODE = None
1814 self.SUB_EXP_CODE = None
1814 self.SUB_EXP_CODE = None
1815 self.PLOT_POS = None
1815 self.PLOT_POS = None
1816
1816
1817 self.__xfilter_ena = False
1817 self.__xfilter_ena = False
1818 self.__yfilter_ena = False
1818 self.__yfilter_ena = False
1819
1819
1820 def getSubplots(self):
1820 def getSubplots(self):
1821
1821
1822 ncol = 3
1822 ncol = 3
1823 nrow = int(numpy.ceil(self.nplots/3.0))
1823 nrow = int(numpy.ceil(self.nplots/3.0))
1824
1824
1825 return nrow, ncol
1825 return nrow, ncol
1826
1826
1827 def setup(self, id, nplots, wintitle, show=True):
1827 def setup(self, id, nplots, wintitle, show=True):
1828
1828
1829 self.nplots = nplots
1829 self.nplots = nplots
1830
1830
1831 ncolspan = 1
1831 ncolspan = 1
1832 colspan = 1
1832 colspan = 1
1833
1833
1834 self.createFigure(id = id,
1834 self.createFigure(id = id,
1835 wintitle = wintitle,
1835 wintitle = wintitle,
1836 widthplot = self.WIDTH + self.WIDTHPROF,
1836 widthplot = self.WIDTH + self.WIDTHPROF,
1837 heightplot = self.HEIGHT + self.HEIGHTPROF,
1837 heightplot = self.HEIGHT + self.HEIGHTPROF,
1838 show=show)
1838 show=show)
1839
1839
1840 nrow, ncol = self.getSubplots()
1840 nrow, ncol = self.getSubplots()
1841
1841
1842 counter = 0
1842 counter = 0
1843 for y in range(nrow):
1843 for y in range(nrow):
1844 for x in range(ncol):
1844 for x in range(ncol):
1845
1845
1846 if counter >= self.nplots:
1846 if counter >= self.nplots:
1847 break
1847 break
1848
1848
1849 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1849 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1850
1850
1851 counter += 1
1851 counter += 1
1852
1852
1853 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
1853 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
1854 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
1854 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
1855 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
1855 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
1856 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1856 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1857 server=None, folder=None, username=None, password=None,
1857 server=None, folder=None, username=None, password=None,
1858 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
1858 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
1859 xaxis="frequency"):
1859 xaxis="frequency"):
1860
1860
1861 """
1861 """
1862
1862
1863 Input:
1863 Input:
1864 dataOut :
1864 dataOut :
1865 id :
1865 id :
1866 wintitle :
1866 wintitle :
1867 channelList :
1867 channelList :
1868 showProfile :
1868 showProfile :
1869 xmin : None,
1869 xmin : None,
1870 xmax : None,
1870 xmax : None,
1871 ymin : None,
1871 ymin : None,
1872 ymax : None,
1872 ymax : None,
1873 zmin : None,
1873 zmin : None,
1874 zmax : None
1874 zmax : None
1875 """
1875 """
1876 #SEPARAR EN DOS PLOTS
1876 #SEPARAR EN DOS PLOTS
1877 nParam = dataOut.data_param.shape[1] - 3
1877 nParam = dataOut.data_param.shape[1] - 3
1878
1878
1879 utctime = dataOut.data_param[0,0]
1879 utctime = dataOut.data_param[0,0]
1880 tmet = dataOut.data_param[:,1].astype(int)
1880 tmet = dataOut.data_param[:,1].astype(int)
1881 hmet = dataOut.data_param[:,2].astype(int)
1881 hmet = dataOut.data_param[:,2].astype(int)
1882
1882
1883 x = dataOut.abscissaList
1883 x = dataOut.abscissaList
1884 y = dataOut.heightList
1884 y = dataOut.heightList
1885
1885
1886 z = numpy.zeros((nParam, y.size, x.size - 1))
1886 z = numpy.zeros((nParam, y.size, x.size - 1))
1887 z[:,:] = numpy.nan
1887 z[:,:] = numpy.nan
1888 z[:,hmet,tmet] = dataOut.data_param[:,3:].T
1888 z[:,hmet,tmet] = dataOut.data_param[:,3:].T
1889 z[0,:,:] = 10*numpy.log10(z[0,:,:])
1889 z[0,:,:] = 10*numpy.log10(z[0,:,:])
1890
1890
1891 xlabel = "Time (s)"
1891 xlabel = "Time (s)"
1892 ylabel = "Range (km)"
1892 ylabel = "Range (km)"
1893
1893
1894 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1894 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1895
1895
1896 if not self.isConfig:
1896 if not self.isConfig:
1897
1897
1898 nplots = nParam
1898 nplots = nParam
1899
1899
1900 self.setup(id=id,
1900 self.setup(id=id,
1901 nplots=nplots,
1901 nplots=nplots,
1902 wintitle=wintitle,
1902 wintitle=wintitle,
1903 show=show)
1903 show=show)
1904
1904
1905 if xmin is None: xmin = numpy.nanmin(x)
1905 if xmin is None: xmin = numpy.nanmin(x)
1906 if xmax is None: xmax = numpy.nanmax(x)
1906 if xmax is None: xmax = numpy.nanmax(x)
1907 if ymin is None: ymin = numpy.nanmin(y)
1907 if ymin is None: ymin = numpy.nanmin(y)
1908 if ymax is None: ymax = numpy.nanmax(y)
1908 if ymax is None: ymax = numpy.nanmax(y)
1909 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
1909 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
1910 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
1910 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
1911 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
1911 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
1912 if vmin is None: vmin = -vmax
1912 if vmin is None: vmin = -vmax
1913 if wmin is None: wmin = 0
1913 if wmin is None: wmin = 0
1914 if wmax is None: wmax = 50
1914 if wmax is None: wmax = 50
1915
1915
1916 pairsList = dataOut.groupList
1916 pairsList = dataOut.groupList
1917 self.nPairs = len(dataOut.groupList)
1917 self.nPairs = len(dataOut.groupList)
1918
1918
1919 zminList = [SNRmin, vmin, cmin] + [pmin]*self.nPairs
1919 zminList = [SNRmin, vmin, cmin] + [pmin]*self.nPairs
1920 zmaxList = [SNRmax, vmax, cmax] + [pmax]*self.nPairs
1920 zmaxList = [SNRmax, vmax, cmax] + [pmax]*self.nPairs
1921 titleList = ["SNR","Radial Velocity","Coherence"]
1921 titleList = ["SNR","Radial Velocity","Coherence"]
1922 cmapList = ["jet","RdBu_r","jet"]
1922 cmapList = ["jet","RdBu_r","jet"]
1923
1923
1924 for i in range(self.nPairs):
1924 for i in range(self.nPairs):
1925 strAux1 = "Phase Difference "+ str(pairsList[i][0]) + str(pairsList[i][1])
1925 strAux1 = "Phase Difference "+ str(pairsList[i][0]) + str(pairsList[i][1])
1926 titleList = titleList + [strAux1]
1926 titleList = titleList + [strAux1]
1927 cmapList = cmapList + ["RdBu_r"]
1927 cmapList = cmapList + ["RdBu_r"]
1928
1928
1929 self.zminList = zminList
1929 self.zminList = zminList
1930 self.zmaxList = zmaxList
1930 self.zmaxList = zmaxList
1931 self.cmapList = cmapList
1931 self.cmapList = cmapList
1932 self.titleList = titleList
1932 self.titleList = titleList
1933
1933
1934 self.FTP_WEI = ftp_wei
1934 self.FTP_WEI = ftp_wei
1935 self.EXP_CODE = exp_code
1935 self.EXP_CODE = exp_code
1936 self.SUB_EXP_CODE = sub_exp_code
1936 self.SUB_EXP_CODE = sub_exp_code
1937 self.PLOT_POS = plot_pos
1937 self.PLOT_POS = plot_pos
1938
1938
1939 self.isConfig = True
1939 self.isConfig = True
1940
1940
1941 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
1941 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
1942
1942
1943 for i in range(nParam):
1943 for i in range(nParam):
1944 title = self.titleList[i] + ": " +str_datetime
1944 title = self.titleList[i] + ": " +str_datetime
1945 axes = self.axesList[i]
1945 axes = self.axesList[i]
1946 axes.pcolor(x, y, z[i,:].T,
1946 axes.pcolor(x, y, z[i,:].T,
1947 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
1947 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
1948 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
1948 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
1949 self.draw()
1949 self.draw()
1950
1950
1951 if figfile == None:
1951 if figfile == None:
1952 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1952 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1953 name = str_datetime
1953 name = str_datetime
1954 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1954 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1955 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
1955 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
1956 figfile = self.getFilename(name)
1956 figfile = self.getFilename(name)
1957
1957
1958 self.save(figpath=figpath,
1958 self.save(figpath=figpath,
1959 figfile=figfile,
1959 figfile=figfile,
1960 save=save,
1960 save=save,
1961 ftp=ftp,
1961 ftp=ftp,
1962 wr_period=wr_period,
1962 wr_period=wr_period,
1963 thisDatetime=thisDatetime)
1963 thisDatetime=thisDatetime)
1964
1964
1965
1965
1966 class NSMeteorDetection2Plot(Figure):
1966 class NSMeteorDetection2Plot(Figure):
1967
1967
1968 isConfig = None
1968 isConfig = None
1969 __nsubplots = None
1969 __nsubplots = None
1970
1970
1971 WIDTHPROF = None
1971 WIDTHPROF = None
1972 HEIGHTPROF = None
1972 HEIGHTPROF = None
1973 PREFIX = 'nsm'
1973 PREFIX = 'nsm'
1974
1974
1975 zminList = None
1975 zminList = None
1976 zmaxList = None
1976 zmaxList = None
1977 cmapList = None
1977 cmapList = None
1978 titleList = None
1978 titleList = None
1979 nPairs = None
1979 nPairs = None
1980 nChannels = None
1980 nChannels = None
1981 nParam = None
1981 nParam = None
1982
1982
1983 def __init__(self, **kwargs):
1983 def __init__(self, **kwargs):
1984 Figure.__init__(self, **kwargs)
1984 Figure.__init__(self, **kwargs)
1985 self.isConfig = False
1985 self.isConfig = False
1986 self.__nsubplots = 1
1986 self.__nsubplots = 1
1987
1987
1988 self.WIDTH = 750
1988 self.WIDTH = 750
1989 self.HEIGHT = 250
1989 self.HEIGHT = 250
1990 self.WIDTHPROF = 120
1990 self.WIDTHPROF = 120
1991 self.HEIGHTPROF = 0
1991 self.HEIGHTPROF = 0
1992 self.counter_imagwr = 0
1992 self.counter_imagwr = 0
1993
1993
1994 self.PLOT_CODE = SPEC_CODE
1994 self.PLOT_CODE = SPEC_CODE
1995
1995
1996 self.FTP_WEI = None
1996 self.FTP_WEI = None
1997 self.EXP_CODE = None
1997 self.EXP_CODE = None
1998 self.SUB_EXP_CODE = None
1998 self.SUB_EXP_CODE = None
1999 self.PLOT_POS = None
1999 self.PLOT_POS = None
2000
2000
2001 self.__xfilter_ena = False
2001 self.__xfilter_ena = False
2002 self.__yfilter_ena = False
2002 self.__yfilter_ena = False
2003
2003
2004 def getSubplots(self):
2004 def getSubplots(self):
2005
2005
2006 ncol = 3
2006 ncol = 3
2007 nrow = int(numpy.ceil(self.nplots/3.0))
2007 nrow = int(numpy.ceil(self.nplots/3.0))
2008
2008
2009 return nrow, ncol
2009 return nrow, ncol
2010
2010
2011 def setup(self, id, nplots, wintitle, show=True):
2011 def setup(self, id, nplots, wintitle, show=True):
2012
2012
2013 self.nplots = nplots
2013 self.nplots = nplots
2014
2014
2015 ncolspan = 1
2015 ncolspan = 1
2016 colspan = 1
2016 colspan = 1
2017
2017
2018 self.createFigure(id = id,
2018 self.createFigure(id = id,
2019 wintitle = wintitle,
2019 wintitle = wintitle,
2020 widthplot = self.WIDTH + self.WIDTHPROF,
2020 widthplot = self.WIDTH + self.WIDTHPROF,
2021 heightplot = self.HEIGHT + self.HEIGHTPROF,
2021 heightplot = self.HEIGHT + self.HEIGHTPROF,
2022 show=show)
2022 show=show)
2023
2023
2024 nrow, ncol = self.getSubplots()
2024 nrow, ncol = self.getSubplots()
2025
2025
2026 counter = 0
2026 counter = 0
2027 for y in range(nrow):
2027 for y in range(nrow):
2028 for x in range(ncol):
2028 for x in range(ncol):
2029
2029
2030 if counter >= self.nplots:
2030 if counter >= self.nplots:
2031 break
2031 break
2032
2032
2033 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
2033 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
2034
2034
2035 counter += 1
2035 counter += 1
2036
2036
2037 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
2037 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
2038 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
2038 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
2039 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
2039 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
2040 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
2040 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
2041 server=None, folder=None, username=None, password=None,
2041 server=None, folder=None, username=None, password=None,
2042 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
2042 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
2043 xaxis="frequency"):
2043 xaxis="frequency"):
2044
2044
2045 """
2045 """
2046
2046
2047 Input:
2047 Input:
2048 dataOut :
2048 dataOut :
2049 id :
2049 id :
2050 wintitle :
2050 wintitle :
2051 channelList :
2051 channelList :
2052 showProfile :
2052 showProfile :
2053 xmin : None,
2053 xmin : None,
2054 xmax : None,
2054 xmax : None,
2055 ymin : None,
2055 ymin : None,
2056 ymax : None,
2056 ymax : None,
2057 zmin : None,
2057 zmin : None,
2058 zmax : None
2058 zmax : None
2059 """
2059 """
2060 #Rebuild matrix
2060 #Rebuild matrix
2061 utctime = dataOut.data_param[0,0]
2061 utctime = dataOut.data_param[0,0]
2062 cmet = dataOut.data_param[:,1].astype(int)
2062 cmet = dataOut.data_param[:,1].astype(int)
2063 tmet = dataOut.data_param[:,2].astype(int)
2063 tmet = dataOut.data_param[:,2].astype(int)
2064 hmet = dataOut.data_param[:,3].astype(int)
2064 hmet = dataOut.data_param[:,3].astype(int)
2065
2065
2066 nParam = 3
2066 nParam = 3
2067 nChan = len(dataOut.groupList)
2067 nChan = len(dataOut.groupList)
2068 x = dataOut.abscissaList
2068 x = dataOut.abscissaList
2069 y = dataOut.heightList
2069 y = dataOut.heightList
2070
2070
2071 z = numpy.full((nChan, nParam, y.size, x.size - 1),numpy.nan)
2071 z = numpy.full((nChan, nParam, y.size, x.size - 1),numpy.nan)
2072 z[cmet,:,hmet,tmet] = dataOut.data_param[:,4:]
2072 z[cmet,:,hmet,tmet] = dataOut.data_param[:,4:]
2073 z[:,0,:,:] = 10*numpy.log10(z[:,0,:,:]) #logarithmic scale
2073 z[:,0,:,:] = 10*numpy.log10(z[:,0,:,:]) #logarithmic scale
2074 z = numpy.reshape(z, (nChan*nParam, y.size, x.size-1))
2074 z = numpy.reshape(z, (nChan*nParam, y.size, x.size-1))
2075
2075
2076 xlabel = "Time (s)"
2076 xlabel = "Time (s)"
2077 ylabel = "Range (km)"
2077 ylabel = "Range (km)"
2078
2078
2079 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
2079 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
2080
2080
2081 if not self.isConfig:
2081 if not self.isConfig:
2082
2082
2083 nplots = nParam*nChan
2083 nplots = nParam*nChan
2084
2084
2085 self.setup(id=id,
2085 self.setup(id=id,
2086 nplots=nplots,
2086 nplots=nplots,
2087 wintitle=wintitle,
2087 wintitle=wintitle,
2088 show=show)
2088 show=show)
2089
2089
2090 if xmin is None: xmin = numpy.nanmin(x)
2090 if xmin is None: xmin = numpy.nanmin(x)
2091 if xmax is None: xmax = numpy.nanmax(x)
2091 if xmax is None: xmax = numpy.nanmax(x)
2092 if ymin is None: ymin = numpy.nanmin(y)
2092 if ymin is None: ymin = numpy.nanmin(y)
2093 if ymax is None: ymax = numpy.nanmax(y)
2093 if ymax is None: ymax = numpy.nanmax(y)
2094 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
2094 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
2095 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
2095 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
2096 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
2096 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
2097 if vmin is None: vmin = -vmax
2097 if vmin is None: vmin = -vmax
2098 if wmin is None: wmin = 0
2098 if wmin is None: wmin = 0
2099 if wmax is None: wmax = 50
2099 if wmax is None: wmax = 50
2100
2100
2101 self.nChannels = nChan
2101 self.nChannels = nChan
2102
2102
2103 zminList = []
2103 zminList = []
2104 zmaxList = []
2104 zmaxList = []
2105 titleList = []
2105 titleList = []
2106 cmapList = []
2106 cmapList = []
2107 for i in range(self.nChannels):
2107 for i in range(self.nChannels):
2108 strAux1 = "SNR Channel "+ str(i)
2108 strAux1 = "SNR Channel "+ str(i)
2109 strAux2 = "Radial Velocity Channel "+ str(i)
2109 strAux2 = "Radial Velocity Channel "+ str(i)
2110 strAux3 = "Spectral Width Channel "+ str(i)
2110 strAux3 = "Spectral Width Channel "+ str(i)
2111
2111
2112 titleList = titleList + [strAux1,strAux2,strAux3]
2112 titleList = titleList + [strAux1,strAux2,strAux3]
2113 cmapList = cmapList + ["jet","RdBu_r","jet"]
2113 cmapList = cmapList + ["jet","RdBu_r","jet"]
2114 zminList = zminList + [SNRmin,vmin,wmin]
2114 zminList = zminList + [SNRmin,vmin,wmin]
2115 zmaxList = zmaxList + [SNRmax,vmax,wmax]
2115 zmaxList = zmaxList + [SNRmax,vmax,wmax]
2116
2116
2117 self.zminList = zminList
2117 self.zminList = zminList
2118 self.zmaxList = zmaxList
2118 self.zmaxList = zmaxList
2119 self.cmapList = cmapList
2119 self.cmapList = cmapList
2120 self.titleList = titleList
2120 self.titleList = titleList
2121
2121
2122 self.FTP_WEI = ftp_wei
2122 self.FTP_WEI = ftp_wei
2123 self.EXP_CODE = exp_code
2123 self.EXP_CODE = exp_code
2124 self.SUB_EXP_CODE = sub_exp_code
2124 self.SUB_EXP_CODE = sub_exp_code
2125 self.PLOT_POS = plot_pos
2125 self.PLOT_POS = plot_pos
2126
2126
2127 self.isConfig = True
2127 self.isConfig = True
2128
2128
2129 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
2129 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
2130
2130
2131 for i in range(self.nplots):
2131 for i in range(self.nplots):
2132 title = self.titleList[i] + ": " +str_datetime
2132 title = self.titleList[i] + ": " +str_datetime
2133 axes = self.axesList[i]
2133 axes = self.axesList[i]
2134 axes.pcolor(x, y, z[i,:].T,
2134 axes.pcolor(x, y, z[i,:].T,
2135 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
2135 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
2136 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
2136 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
2137 self.draw()
2137 self.draw()
2138
2138
2139 if figfile == None:
2139 if figfile == None:
2140 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
2140 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
2141 name = str_datetime
2141 name = str_datetime
2142 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
2142 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
2143 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
2143 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
2144 figfile = self.getFilename(name)
2144 figfile = self.getFilename(name)
2145
2145
2146 self.save(figpath=figpath,
2146 self.save(figpath=figpath,
2147 figfile=figfile,
2147 figfile=figfile,
2148 save=save,
2148 save=save,
2149 ftp=ftp,
2149 ftp=ftp,
2150 wr_period=wr_period,
2150 wr_period=wr_period,
2151 thisDatetime=thisDatetime)
2151 thisDatetime=thisDatetime) No newline at end of file
@@ -1,1542 +1,1542
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
13
14 class SpectraPlot(Figure):
14 class SpectraPlot(Figure):
15
15
16 isConfig = None
16 isConfig = None
17 __nsubplots = None
17 __nsubplots = None
18
18
19 WIDTHPROF = None
19 WIDTHPROF = None
20 HEIGHTPROF = None
20 HEIGHTPROF = None
21 PREFIX = 'spc'
21 PREFIX = 'spc'
22
22
23 def __init__(self, **kwargs):
23 def __init__(self, **kwargs):
24 Figure.__init__(self, **kwargs)
24 Figure.__init__(self, **kwargs)
25 self.isConfig = False
25 self.isConfig = False
26 self.__nsubplots = 1
26 self.__nsubplots = 1
27
27
28 self.WIDTH = 250
28 self.WIDTH = 250
29 self.HEIGHT = 250
29 self.HEIGHT = 250
30 self.WIDTHPROF = 120
30 self.WIDTHPROF = 120
31 self.HEIGHTPROF = 0
31 self.HEIGHTPROF = 0
32 self.counter_imagwr = 0
32 self.counter_imagwr = 0
33
33
34 self.PLOT_CODE = SPEC_CODE
34 self.PLOT_CODE = SPEC_CODE
35
35
36 self.FTP_WEI = None
36 self.FTP_WEI = None
37 self.EXP_CODE = None
37 self.EXP_CODE = None
38 self.SUB_EXP_CODE = None
38 self.SUB_EXP_CODE = None
39 self.PLOT_POS = None
39 self.PLOT_POS = None
40
40
41 self.__xfilter_ena = False
41 self.__xfilter_ena = False
42 self.__yfilter_ena = False
42 self.__yfilter_ena = False
43
43
44 def getSubplots(self):
44 def getSubplots(self):
45
45
46 ncol = int(numpy.sqrt(self.nplots)+0.9)
46 ncol = int(numpy.sqrt(self.nplots)+0.9)
47 nrow = int(self.nplots*1./ncol + 0.9)
47 nrow = int(self.nplots*1./ncol + 0.9)
48
48
49 return nrow, ncol
49 return nrow, ncol
50
50
51 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
51 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
52
52
53 self.__showprofile = showprofile
53 self.__showprofile = showprofile
54 self.nplots = nplots
54 self.nplots = nplots
55
55
56 ncolspan = 1
56 ncolspan = 1
57 colspan = 1
57 colspan = 1
58 if showprofile:
58 if showprofile:
59 ncolspan = 3
59 ncolspan = 3
60 colspan = 2
60 colspan = 2
61 self.__nsubplots = 2
61 self.__nsubplots = 2
62
62
63 self.createFigure(id = id,
63 self.createFigure(id = id,
64 wintitle = wintitle,
64 wintitle = wintitle,
65 widthplot = self.WIDTH + self.WIDTHPROF,
65 widthplot = self.WIDTH + self.WIDTHPROF,
66 heightplot = self.HEIGHT + self.HEIGHTPROF,
66 heightplot = self.HEIGHT + self.HEIGHTPROF,
67 show=show)
67 show=show)
68
68
69 nrow, ncol = self.getSubplots()
69 nrow, ncol = self.getSubplots()
70
70
71 counter = 0
71 counter = 0
72 for y in range(nrow):
72 for y in range(nrow):
73 for x in range(ncol):
73 for x in range(ncol):
74
74
75 if counter >= self.nplots:
75 if counter >= self.nplots:
76 break
76 break
77
77
78 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
78 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
79
79
80 if showprofile:
80 if showprofile:
81 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
81 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
82
82
83 counter += 1
83 counter += 1
84
84
85 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
85 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
86 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
86 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
87 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
87 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
88 server=None, folder=None, username=None, password=None,
88 server=None, folder=None, username=None, password=None,
89 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
89 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
90 xaxis="frequency", colormap='jet', normFactor=None):
90 xaxis="frequency", colormap='jet', normFactor=None):
91
91
92 """
92 """
93
93
94 Input:
94 Input:
95 dataOut :
95 dataOut :
96 id :
96 id :
97 wintitle :
97 wintitle :
98 channelList :
98 channelList :
99 showProfile :
99 showProfile :
100 xmin : None,
100 xmin : None,
101 xmax : None,
101 xmax : None,
102 ymin : None,
102 ymin : None,
103 ymax : None,
103 ymax : None,
104 zmin : None,
104 zmin : None,
105 zmax : None
105 zmax : None
106 """
106 """
107 if realtime:
107 if realtime:
108 if not(isRealtime(utcdatatime = dataOut.utctime)):
108 if not(isRealtime(utcdatatime = dataOut.utctime)):
109 print 'Skipping this plot function'
109 print('Skipping this plot function')
110 return
110 return
111
111
112 if channelList == None:
112 if channelList == None:
113 channelIndexList = dataOut.channelIndexList
113 channelIndexList = dataOut.channelIndexList
114 else:
114 else:
115 channelIndexList = []
115 channelIndexList = []
116 for channel in channelList:
116 for channel in channelList:
117 if channel not in dataOut.channelList:
117 if channel not in dataOut.channelList:
118 raise ValueError, "Channel %d is not in dataOut.channelList" %channel
118 raise ValueError("Channel %d is not in dataOut.channelList" %channel)
119 channelIndexList.append(dataOut.channelList.index(channel))
119 channelIndexList.append(dataOut.channelList.index(channel))
120
120
121 if normFactor is None:
121 if normFactor is None:
122 factor = dataOut.normFactor
122 factor = dataOut.normFactor
123 else:
123 else:
124 factor = normFactor
124 factor = normFactor
125 if xaxis == "frequency":
125 if xaxis == "frequency":
126 x = dataOut.getFreqRange(1)/1000.
126 x = dataOut.getFreqRange(1)/1000.
127 xlabel = "Frequency (kHz)"
127 xlabel = "Frequency (kHz)"
128
128
129 elif xaxis == "time":
129 elif xaxis == "time":
130 x = dataOut.getAcfRange(1)
130 x = dataOut.getAcfRange(1)
131 xlabel = "Time (ms)"
131 xlabel = "Time (ms)"
132
132
133 else:
133 else:
134 x = dataOut.getVelRange(1)
134 x = dataOut.getVelRange(1)
135 xlabel = "Velocity (m/s)"
135 xlabel = "Velocity (m/s)"
136
136
137 ylabel = "Range (Km)"
137 ylabel = "Range (Km)"
138
138
139 y = dataOut.getHeiRange()
139 y = dataOut.getHeiRange()
140
140
141 z = dataOut.data_spc/factor
141 z = dataOut.data_spc/factor
142 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
142 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
143 zdB = 10*numpy.log10(z)
143 zdB = 10*numpy.log10(z)
144
144
145 avg = numpy.average(z, axis=1)
145 avg = numpy.average(z, axis=1)
146 avgdB = 10*numpy.log10(avg)
146 avgdB = 10*numpy.log10(avg)
147
147
148 noise = dataOut.getNoise()/factor
148 noise = dataOut.getNoise()/factor
149 noisedB = 10*numpy.log10(noise)
149 noisedB = 10*numpy.log10(noise)
150
150
151 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
151 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
152 title = wintitle + " Spectra"
152 title = wintitle + " Spectra"
153 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
153 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
154 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)
155
155
156 if not self.isConfig:
156 if not self.isConfig:
157
157
158 nplots = len(channelIndexList)
158 nplots = len(channelIndexList)
159
159
160 self.setup(id=id,
160 self.setup(id=id,
161 nplots=nplots,
161 nplots=nplots,
162 wintitle=wintitle,
162 wintitle=wintitle,
163 showprofile=showprofile,
163 showprofile=showprofile,
164 show=show)
164 show=show)
165
165
166 if xmin == None: xmin = numpy.nanmin(x)
166 if xmin == None: xmin = numpy.nanmin(x)
167 if xmax == None: xmax = numpy.nanmax(x)
167 if xmax == None: xmax = numpy.nanmax(x)
168 if ymin == None: ymin = numpy.nanmin(y)
168 if ymin == None: ymin = numpy.nanmin(y)
169 if ymax == None: ymax = numpy.nanmax(y)
169 if ymax == None: ymax = numpy.nanmax(y)
170 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
170 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
171 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
171 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
172
172
173 self.FTP_WEI = ftp_wei
173 self.FTP_WEI = ftp_wei
174 self.EXP_CODE = exp_code
174 self.EXP_CODE = exp_code
175 self.SUB_EXP_CODE = sub_exp_code
175 self.SUB_EXP_CODE = sub_exp_code
176 self.PLOT_POS = plot_pos
176 self.PLOT_POS = plot_pos
177
177
178 self.isConfig = True
178 self.isConfig = True
179
179
180 self.setWinTitle(title)
180 self.setWinTitle(title)
181
181
182 for i in range(self.nplots):
182 for i in range(self.nplots):
183 index = channelIndexList[i]
183 index = channelIndexList[i]
184 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"))
185 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)
186 if len(dataOut.beam.codeList) != 0:
186 if len(dataOut.beam.codeList) != 0:
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)
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)
188
188
189 axes = self.axesList[i*self.__nsubplots]
189 axes = self.axesList[i*self.__nsubplots]
190 axes.pcolor(x, y, zdB[index,:,:],
190 axes.pcolor(x, y, zdB[index,:,:],
191 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,
192 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
192 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
193 ticksize=9, cblabel='')
193 ticksize=9, cblabel='')
194
194
195 if self.__showprofile:
195 if self.__showprofile:
196 axes = self.axesList[i*self.__nsubplots +1]
196 axes = self.axesList[i*self.__nsubplots +1]
197 axes.pline(avgdB[index,:], y,
197 axes.pline(avgdB[index,:], y,
198 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
198 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
199 xlabel='dB', ylabel='', title='',
199 xlabel='dB', ylabel='', title='',
200 ytick_visible=False,
200 ytick_visible=False,
201 grid='x')
201 grid='x')
202
202
203 noiseline = numpy.repeat(noisedB[index], len(y))
203 noiseline = numpy.repeat(noisedB[index], len(y))
204 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)
205
205
206 self.draw()
206 self.draw()
207
207
208 if figfile == None:
208 if figfile == None:
209 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
209 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
210 name = str_datetime
210 name = str_datetime
211 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
211 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
212 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)
213 figfile = self.getFilename(name)
213 figfile = self.getFilename(name)
214
214
215 self.save(figpath=figpath,
215 self.save(figpath=figpath,
216 figfile=figfile,
216 figfile=figfile,
217 save=save,
217 save=save,
218 ftp=ftp,
218 ftp=ftp,
219 wr_period=wr_period,
219 wr_period=wr_period,
220 thisDatetime=thisDatetime)
220 thisDatetime=thisDatetime)
221
221
222 class CrossSpectraPlot(Figure):
222 class CrossSpectraPlot(Figure):
223
223
224 isConfig = None
224 isConfig = None
225 __nsubplots = None
225 __nsubplots = None
226
226
227 WIDTH = None
227 WIDTH = None
228 HEIGHT = None
228 HEIGHT = None
229 WIDTHPROF = None
229 WIDTHPROF = None
230 HEIGHTPROF = None
230 HEIGHTPROF = None
231 PREFIX = 'cspc'
231 PREFIX = 'cspc'
232
232
233 def __init__(self, **kwargs):
233 def __init__(self, **kwargs):
234 Figure.__init__(self, **kwargs)
234 Figure.__init__(self, **kwargs)
235 self.isConfig = False
235 self.isConfig = False
236 self.__nsubplots = 4
236 self.__nsubplots = 4
237 self.counter_imagwr = 0
237 self.counter_imagwr = 0
238 self.WIDTH = 250
238 self.WIDTH = 250
239 self.HEIGHT = 250
239 self.HEIGHT = 250
240 self.WIDTHPROF = 0
240 self.WIDTHPROF = 0
241 self.HEIGHTPROF = 0
241 self.HEIGHTPROF = 0
242
242
243 self.PLOT_CODE = CROSS_CODE
243 self.PLOT_CODE = CROSS_CODE
244 self.FTP_WEI = None
244 self.FTP_WEI = None
245 self.EXP_CODE = None
245 self.EXP_CODE = None
246 self.SUB_EXP_CODE = None
246 self.SUB_EXP_CODE = None
247 self.PLOT_POS = None
247 self.PLOT_POS = None
248
248
249 def getSubplots(self):
249 def getSubplots(self):
250
250
251 ncol = 4
251 ncol = 4
252 nrow = self.nplots
252 nrow = self.nplots
253
253
254 return nrow, ncol
254 return nrow, ncol
255
255
256 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
256 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
257
257
258 self.__showprofile = showprofile
258 self.__showprofile = showprofile
259 self.nplots = nplots
259 self.nplots = nplots
260
260
261 ncolspan = 1
261 ncolspan = 1
262 colspan = 1
262 colspan = 1
263
263
264 self.createFigure(id = id,
264 self.createFigure(id = id,
265 wintitle = wintitle,
265 wintitle = wintitle,
266 widthplot = self.WIDTH + self.WIDTHPROF,
266 widthplot = self.WIDTH + self.WIDTHPROF,
267 heightplot = self.HEIGHT + self.HEIGHTPROF,
267 heightplot = self.HEIGHT + self.HEIGHTPROF,
268 show=True)
268 show=True)
269
269
270 nrow, ncol = self.getSubplots()
270 nrow, ncol = self.getSubplots()
271
271
272 counter = 0
272 counter = 0
273 for y in range(nrow):
273 for y in range(nrow):
274 for x in range(ncol):
274 for x in range(ncol):
275 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
275 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
276
276
277 counter += 1
277 counter += 1
278
278
279 def run(self, dataOut, id, wintitle="", pairsList=None,
279 def run(self, dataOut, id, wintitle="", pairsList=None,
280 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,
281 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,
282 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
282 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
283 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,
284 server=None, folder=None, username=None, password=None,
284 server=None, folder=None, username=None, password=None,
285 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None,
285 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None,
286 xaxis='frequency'):
286 xaxis='frequency'):
287
287
288 """
288 """
289
289
290 Input:
290 Input:
291 dataOut :
291 dataOut :
292 id :
292 id :
293 wintitle :
293 wintitle :
294 channelList :
294 channelList :
295 showProfile :
295 showProfile :
296 xmin : None,
296 xmin : None,
297 xmax : None,
297 xmax : None,
298 ymin : None,
298 ymin : None,
299 ymax : None,
299 ymax : None,
300 zmin : None,
300 zmin : None,
301 zmax : None
301 zmax : None
302 """
302 """
303
303
304 if pairsList == None:
304 if pairsList == None:
305 pairsIndexList = dataOut.pairsIndexList
305 pairsIndexList = dataOut.pairsIndexList
306 else:
306 else:
307 pairsIndexList = []
307 pairsIndexList = []
308 for pair in pairsList:
308 for pair in pairsList:
309 if pair not in dataOut.pairsList:
309 if pair not in dataOut.pairsList:
310 raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair)
310 raise ValueError("Pair %s is not in dataOut.pairsList" %str(pair))
311 pairsIndexList.append(dataOut.pairsList.index(pair))
311 pairsIndexList.append(dataOut.pairsList.index(pair))
312
312
313 if not pairsIndexList:
313 if not pairsIndexList:
314 return
314 return
315
315
316 if len(pairsIndexList) > 4:
316 if len(pairsIndexList) > 4:
317 pairsIndexList = pairsIndexList[0:4]
317 pairsIndexList = pairsIndexList[0:4]
318
318
319 if normFactor is None:
319 if normFactor is None:
320 factor = dataOut.normFactor
320 factor = dataOut.normFactor
321 else:
321 else:
322 factor = normFactor
322 factor = normFactor
323 x = dataOut.getVelRange(1)
323 x = dataOut.getVelRange(1)
324 y = dataOut.getHeiRange()
324 y = dataOut.getHeiRange()
325 z = dataOut.data_spc[:,:,:]/factor
325 z = dataOut.data_spc[:,:,:]/factor
326 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
326 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
327
327
328 noise = dataOut.noise/factor
328 noise = dataOut.noise/factor
329
329
330 zdB = 10*numpy.log10(z)
330 zdB = 10*numpy.log10(z)
331 noisedB = 10*numpy.log10(noise)
331 noisedB = 10*numpy.log10(noise)
332
332
333 if coh_min == None:
333 if coh_min == None:
334 coh_min = 0.0
334 coh_min = 0.0
335 if coh_max == None:
335 if coh_max == None:
336 coh_max = 1.0
336 coh_max = 1.0
337
337
338 if phase_min == None:
338 if phase_min == None:
339 phase_min = -180
339 phase_min = -180
340 if phase_max == None:
340 if phase_max == None:
341 phase_max = 180
341 phase_max = 180
342
342
343 #thisDatetime = dataOut.datatime
343 #thisDatetime = dataOut.datatime
344 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
344 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
345 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
345 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
346 # xlabel = "Velocity (m/s)"
346 # xlabel = "Velocity (m/s)"
347 ylabel = "Range (Km)"
347 ylabel = "Range (Km)"
348
348
349 if xaxis == "frequency":
349 if xaxis == "frequency":
350 x = dataOut.getFreqRange(1)/1000.
350 x = dataOut.getFreqRange(1)/1000.
351 xlabel = "Frequency (kHz)"
351 xlabel = "Frequency (kHz)"
352
352
353 elif xaxis == "time":
353 elif xaxis == "time":
354 x = dataOut.getAcfRange(1)
354 x = dataOut.getAcfRange(1)
355 xlabel = "Time (ms)"
355 xlabel = "Time (ms)"
356
356
357 else:
357 else:
358 x = dataOut.getVelRange(1)
358 x = dataOut.getVelRange(1)
359 xlabel = "Velocity (m/s)"
359 xlabel = "Velocity (m/s)"
360
360
361 if not self.isConfig:
361 if not self.isConfig:
362
362
363 nplots = len(pairsIndexList)
363 nplots = len(pairsIndexList)
364
364
365 self.setup(id=id,
365 self.setup(id=id,
366 nplots=nplots,
366 nplots=nplots,
367 wintitle=wintitle,
367 wintitle=wintitle,
368 showprofile=False,
368 showprofile=False,
369 show=show)
369 show=show)
370
370
371 avg = numpy.abs(numpy.average(z, axis=1))
371 avg = numpy.abs(numpy.average(z, axis=1))
372 avgdB = 10*numpy.log10(avg)
372 avgdB = 10*numpy.log10(avg)
373
373
374 if xmin == None: xmin = numpy.nanmin(x)
374 if xmin == None: xmin = numpy.nanmin(x)
375 if xmax == None: xmax = numpy.nanmax(x)
375 if xmax == None: xmax = numpy.nanmax(x)
376 if ymin == None: ymin = numpy.nanmin(y)
376 if ymin == None: ymin = numpy.nanmin(y)
377 if ymax == None: ymax = numpy.nanmax(y)
377 if ymax == None: ymax = numpy.nanmax(y)
378 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
378 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
379 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
379 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
380
380
381 self.FTP_WEI = ftp_wei
381 self.FTP_WEI = ftp_wei
382 self.EXP_CODE = exp_code
382 self.EXP_CODE = exp_code
383 self.SUB_EXP_CODE = sub_exp_code
383 self.SUB_EXP_CODE = sub_exp_code
384 self.PLOT_POS = plot_pos
384 self.PLOT_POS = plot_pos
385
385
386 self.isConfig = True
386 self.isConfig = True
387
387
388 self.setWinTitle(title)
388 self.setWinTitle(title)
389
389
390 for i in range(self.nplots):
390 for i in range(self.nplots):
391 pair = dataOut.pairsList[pairsIndexList[i]]
391 pair = dataOut.pairsList[pairsIndexList[i]]
392
392
393 chan_index0 = dataOut.channelList.index(pair[0])
393 chan_index0 = dataOut.channelList.index(pair[0])
394 chan_index1 = dataOut.channelList.index(pair[1])
394 chan_index1 = dataOut.channelList.index(pair[1])
395
395
396 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
396 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
397 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime)
397 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime)
398 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor)
398 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor)
399 axes0 = self.axesList[i*self.__nsubplots]
399 axes0 = self.axesList[i*self.__nsubplots]
400 axes0.pcolor(x, y, zdB,
400 axes0.pcolor(x, y, zdB,
401 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
401 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
402 xlabel=xlabel, ylabel=ylabel, title=title,
402 xlabel=xlabel, ylabel=ylabel, title=title,
403 ticksize=9, colormap=power_cmap, cblabel='')
403 ticksize=9, colormap=power_cmap, cblabel='')
404
404
405 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime)
405 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime)
406 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor)
406 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor)
407 axes0 = self.axesList[i*self.__nsubplots+1]
407 axes0 = self.axesList[i*self.__nsubplots+1]
408 axes0.pcolor(x, y, zdB,
408 axes0.pcolor(x, y, zdB,
409 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
409 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
410 xlabel=xlabel, ylabel=ylabel, title=title,
410 xlabel=xlabel, ylabel=ylabel, title=title,
411 ticksize=9, colormap=power_cmap, cblabel='')
411 ticksize=9, colormap=power_cmap, cblabel='')
412
412
413 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:])
413 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:])
414 coherence = numpy.abs(coherenceComplex)
414 coherence = numpy.abs(coherenceComplex)
415 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
415 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
416 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
416 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
417
417
418 title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1])
418 title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1])
419 axes0 = self.axesList[i*self.__nsubplots+2]
419 axes0 = self.axesList[i*self.__nsubplots+2]
420 axes0.pcolor(x, y, coherence,
420 axes0.pcolor(x, y, coherence,
421 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max,
421 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max,
422 xlabel=xlabel, ylabel=ylabel, title=title,
422 xlabel=xlabel, ylabel=ylabel, title=title,
423 ticksize=9, colormap=coherence_cmap, cblabel='')
423 ticksize=9, colormap=coherence_cmap, cblabel='')
424
424
425 title = "Phase Ch%d * Ch%d" %(pair[0], pair[1])
425 title = "Phase Ch%d * Ch%d" %(pair[0], pair[1])
426 axes0 = self.axesList[i*self.__nsubplots+3]
426 axes0 = self.axesList[i*self.__nsubplots+3]
427 axes0.pcolor(x, y, phase,
427 axes0.pcolor(x, y, phase,
428 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
428 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
429 xlabel=xlabel, ylabel=ylabel, title=title,
429 xlabel=xlabel, ylabel=ylabel, title=title,
430 ticksize=9, colormap=phase_cmap, cblabel='')
430 ticksize=9, colormap=phase_cmap, cblabel='')
431
431
432
432
433
433
434 self.draw()
434 self.draw()
435
435
436 self.save(figpath=figpath,
436 self.save(figpath=figpath,
437 figfile=figfile,
437 figfile=figfile,
438 save=save,
438 save=save,
439 ftp=ftp,
439 ftp=ftp,
440 wr_period=wr_period,
440 wr_period=wr_period,
441 thisDatetime=thisDatetime)
441 thisDatetime=thisDatetime)
442
442
443
443
444 class RTIPlot(Figure):
444 class RTIPlot(Figure):
445
445
446 __isConfig = None
446 __isConfig = None
447 __nsubplots = None
447 __nsubplots = None
448
448
449 WIDTHPROF = None
449 WIDTHPROF = None
450 HEIGHTPROF = None
450 HEIGHTPROF = None
451 PREFIX = 'rti'
451 PREFIX = 'rti'
452
452
453 def __init__(self, **kwargs):
453 def __init__(self, **kwargs):
454
454
455 Figure.__init__(self, **kwargs)
455 Figure.__init__(self, **kwargs)
456 self.timerange = None
456 self.timerange = None
457 self.isConfig = False
457 self.isConfig = False
458 self.__nsubplots = 1
458 self.__nsubplots = 1
459
459
460 self.WIDTH = 800
460 self.WIDTH = 800
461 self.HEIGHT = 180
461 self.HEIGHT = 180
462 self.WIDTHPROF = 120
462 self.WIDTHPROF = 120
463 self.HEIGHTPROF = 0
463 self.HEIGHTPROF = 0
464 self.counter_imagwr = 0
464 self.counter_imagwr = 0
465
465
466 self.PLOT_CODE = RTI_CODE
466 self.PLOT_CODE = RTI_CODE
467
467
468 self.FTP_WEI = None
468 self.FTP_WEI = None
469 self.EXP_CODE = None
469 self.EXP_CODE = None
470 self.SUB_EXP_CODE = None
470 self.SUB_EXP_CODE = None
471 self.PLOT_POS = None
471 self.PLOT_POS = None
472 self.tmin = None
472 self.tmin = None
473 self.tmax = None
473 self.tmax = None
474
474
475 self.xmin = None
475 self.xmin = None
476 self.xmax = None
476 self.xmax = None
477
477
478 self.figfile = None
478 self.figfile = None
479
479
480 def getSubplots(self):
480 def getSubplots(self):
481
481
482 ncol = 1
482 ncol = 1
483 nrow = self.nplots
483 nrow = self.nplots
484
484
485 return nrow, ncol
485 return nrow, ncol
486
486
487 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
487 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
488
488
489 self.__showprofile = showprofile
489 self.__showprofile = showprofile
490 self.nplots = nplots
490 self.nplots = nplots
491
491
492 ncolspan = 1
492 ncolspan = 1
493 colspan = 1
493 colspan = 1
494 if showprofile:
494 if showprofile:
495 ncolspan = 7
495 ncolspan = 7
496 colspan = 6
496 colspan = 6
497 self.__nsubplots = 2
497 self.__nsubplots = 2
498
498
499 self.createFigure(id = id,
499 self.createFigure(id = id,
500 wintitle = wintitle,
500 wintitle = wintitle,
501 widthplot = self.WIDTH + self.WIDTHPROF,
501 widthplot = self.WIDTH + self.WIDTHPROF,
502 heightplot = self.HEIGHT + self.HEIGHTPROF,
502 heightplot = self.HEIGHT + self.HEIGHTPROF,
503 show=show)
503 show=show)
504
504
505 nrow, ncol = self.getSubplots()
505 nrow, ncol = self.getSubplots()
506
506
507 counter = 0
507 counter = 0
508 for y in range(nrow):
508 for y in range(nrow):
509 for x in range(ncol):
509 for x in range(ncol):
510
510
511 if counter >= self.nplots:
511 if counter >= self.nplots:
512 break
512 break
513
513
514 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
514 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
515
515
516 if showprofile:
516 if showprofile:
517 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
517 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
518
518
519 counter += 1
519 counter += 1
520
520
521 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
521 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
522 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
522 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
523 timerange=None, colormap='jet',
523 timerange=None, colormap='jet',
524 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
524 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
525 server=None, folder=None, username=None, password=None,
525 server=None, folder=None, username=None, password=None,
526 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None, HEIGHT=None):
526 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None, HEIGHT=None):
527
527
528 """
528 """
529
529
530 Input:
530 Input:
531 dataOut :
531 dataOut :
532 id :
532 id :
533 wintitle :
533 wintitle :
534 channelList :
534 channelList :
535 showProfile :
535 showProfile :
536 xmin : None,
536 xmin : None,
537 xmax : None,
537 xmax : None,
538 ymin : None,
538 ymin : None,
539 ymax : None,
539 ymax : None,
540 zmin : None,
540 zmin : None,
541 zmax : None
541 zmax : None
542 """
542 """
543
543
544 #colormap = kwargs.get('colormap', 'jet')
544 #colormap = kwargs.get('colormap', 'jet')
545 if HEIGHT is not None:
545 if HEIGHT is not None:
546 self.HEIGHT = HEIGHT
546 self.HEIGHT = HEIGHT
547
547
548 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
548 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
549 return
549 return
550
550
551 if channelList == None:
551 if channelList == None:
552 channelIndexList = dataOut.channelIndexList
552 channelIndexList = dataOut.channelIndexList
553 else:
553 else:
554 channelIndexList = []
554 channelIndexList = []
555 for channel in channelList:
555 for channel in channelList:
556 if channel not in dataOut.channelList:
556 if channel not in dataOut.channelList:
557 raise ValueError, "Channel %d is not in dataOut.channelList"
557 raise ValueError("Channel %d is not in dataOut.channelList")
558 channelIndexList.append(dataOut.channelList.index(channel))
558 channelIndexList.append(dataOut.channelList.index(channel))
559
559
560 if normFactor is None:
560 if normFactor is None:
561 factor = dataOut.normFactor
561 factor = dataOut.normFactor
562 else:
562 else:
563 factor = normFactor
563 factor = normFactor
564
564
565 # factor = dataOut.normFactor
565 # factor = dataOut.normFactor
566 x = dataOut.getTimeRange()
566 x = dataOut.getTimeRange()
567 y = dataOut.getHeiRange()
567 y = dataOut.getHeiRange()
568
568
569 z = dataOut.data_spc/factor
569 z = dataOut.data_spc/factor
570 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
570 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
571 avg = numpy.average(z, axis=1)
571 avg = numpy.average(z, axis=1)
572 avgdB = 10.*numpy.log10(avg)
572 avgdB = 10.*numpy.log10(avg)
573 # avgdB = dataOut.getPower()
573 # avgdB = dataOut.getPower()
574
574
575
575
576 thisDatetime = dataOut.datatime
576 thisDatetime = dataOut.datatime
577 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
577 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
578 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
578 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
579 xlabel = ""
579 xlabel = ""
580 ylabel = "Range (Km)"
580 ylabel = "Range (Km)"
581
581
582 update_figfile = False
582 update_figfile = False
583
583
584 if dataOut.ltctime >= self.xmax:
584 if self.xmax is not None and dataOut.ltctime >= self.xmax: #yong
585 self.counter_imagwr = wr_period
585 self.counter_imagwr = wr_period
586 self.isConfig = False
586 self.isConfig = False
587 update_figfile = True
587 update_figfile = True
588
588
589 if not self.isConfig:
589 if not self.isConfig:
590
590
591 nplots = len(channelIndexList)
591 nplots = len(channelIndexList)
592
592
593 self.setup(id=id,
593 self.setup(id=id,
594 nplots=nplots,
594 nplots=nplots,
595 wintitle=wintitle,
595 wintitle=wintitle,
596 showprofile=showprofile,
596 showprofile=showprofile,
597 show=show)
597 show=show)
598
598
599 if timerange != None:
599 if timerange != None:
600 self.timerange = timerange
600 self.timerange = timerange
601
601
602 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
602 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
603
603
604 noise = dataOut.noise/factor
604 noise = dataOut.noise/factor
605 noisedB = 10*numpy.log10(noise)
605 noisedB = 10*numpy.log10(noise)
606
606
607 if ymin == None: ymin = numpy.nanmin(y)
607 if ymin == None: ymin = numpy.nanmin(y)
608 if ymax == None: ymax = numpy.nanmax(y)
608 if ymax == None: ymax = numpy.nanmax(y)
609 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
609 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
610 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
610 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
611
611
612 self.FTP_WEI = ftp_wei
612 self.FTP_WEI = ftp_wei
613 self.EXP_CODE = exp_code
613 self.EXP_CODE = exp_code
614 self.SUB_EXP_CODE = sub_exp_code
614 self.SUB_EXP_CODE = sub_exp_code
615 self.PLOT_POS = plot_pos
615 self.PLOT_POS = plot_pos
616
616
617 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
617 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
618 self.isConfig = True
618 self.isConfig = True
619 self.figfile = figfile
619 self.figfile = figfile
620 update_figfile = True
620 update_figfile = True
621
621
622 self.setWinTitle(title)
622 self.setWinTitle(title)
623
623
624 for i in range(self.nplots):
624 for i in range(self.nplots):
625 index = channelIndexList[i]
625 index = channelIndexList[i]
626 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
626 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
627 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
627 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
628 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
628 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
629 axes = self.axesList[i*self.__nsubplots]
629 axes = self.axesList[i*self.__nsubplots]
630 zdB = avgdB[index].reshape((1,-1))
630 zdB = avgdB[index].reshape((1,-1))
631 axes.pcolorbuffer(x, y, zdB,
631 axes.pcolorbuffer(x, y, zdB,
632 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
632 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
633 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
633 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
634 ticksize=9, cblabel='', cbsize="1%", colormap=colormap)
634 ticksize=9, cblabel='', cbsize="1%", colormap=colormap)
635
635
636 if self.__showprofile:
636 if self.__showprofile:
637 axes = self.axesList[i*self.__nsubplots +1]
637 axes = self.axesList[i*self.__nsubplots +1]
638 axes.pline(avgdB[index], y,
638 axes.pline(avgdB[index], y,
639 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
639 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
640 xlabel='dB', ylabel='', title='',
640 xlabel='dB', ylabel='', title='',
641 ytick_visible=False,
641 ytick_visible=False,
642 grid='x')
642 grid='x')
643
643
644 self.draw()
644 self.draw()
645
645
646 self.save(figpath=figpath,
646 self.save(figpath=figpath,
647 figfile=figfile,
647 figfile=figfile,
648 save=save,
648 save=save,
649 ftp=ftp,
649 ftp=ftp,
650 wr_period=wr_period,
650 wr_period=wr_period,
651 thisDatetime=thisDatetime,
651 thisDatetime=thisDatetime,
652 update_figfile=update_figfile)
652 update_figfile=update_figfile)
653
653
654 class CoherenceMap(Figure):
654 class CoherenceMap(Figure):
655 isConfig = None
655 isConfig = None
656 __nsubplots = None
656 __nsubplots = None
657
657
658 WIDTHPROF = None
658 WIDTHPROF = None
659 HEIGHTPROF = None
659 HEIGHTPROF = None
660 PREFIX = 'cmap'
660 PREFIX = 'cmap'
661
661
662 def __init__(self, **kwargs):
662 def __init__(self, **kwargs):
663 Figure.__init__(self, **kwargs)
663 Figure.__init__(self, **kwargs)
664 self.timerange = 2*60*60
664 self.timerange = 2*60*60
665 self.isConfig = False
665 self.isConfig = False
666 self.__nsubplots = 1
666 self.__nsubplots = 1
667
667
668 self.WIDTH = 800
668 self.WIDTH = 800
669 self.HEIGHT = 180
669 self.HEIGHT = 180
670 self.WIDTHPROF = 120
670 self.WIDTHPROF = 120
671 self.HEIGHTPROF = 0
671 self.HEIGHTPROF = 0
672 self.counter_imagwr = 0
672 self.counter_imagwr = 0
673
673
674 self.PLOT_CODE = COH_CODE
674 self.PLOT_CODE = COH_CODE
675
675
676 self.FTP_WEI = None
676 self.FTP_WEI = None
677 self.EXP_CODE = None
677 self.EXP_CODE = None
678 self.SUB_EXP_CODE = None
678 self.SUB_EXP_CODE = None
679 self.PLOT_POS = None
679 self.PLOT_POS = None
680 self.counter_imagwr = 0
680 self.counter_imagwr = 0
681
681
682 self.xmin = None
682 self.xmin = None
683 self.xmax = None
683 self.xmax = None
684
684
685 def getSubplots(self):
685 def getSubplots(self):
686 ncol = 1
686 ncol = 1
687 nrow = self.nplots*2
687 nrow = self.nplots*2
688
688
689 return nrow, ncol
689 return nrow, ncol
690
690
691 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
691 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
692 self.__showprofile = showprofile
692 self.__showprofile = showprofile
693 self.nplots = nplots
693 self.nplots = nplots
694
694
695 ncolspan = 1
695 ncolspan = 1
696 colspan = 1
696 colspan = 1
697 if showprofile:
697 if showprofile:
698 ncolspan = 7
698 ncolspan = 7
699 colspan = 6
699 colspan = 6
700 self.__nsubplots = 2
700 self.__nsubplots = 2
701
701
702 self.createFigure(id = id,
702 self.createFigure(id = id,
703 wintitle = wintitle,
703 wintitle = wintitle,
704 widthplot = self.WIDTH + self.WIDTHPROF,
704 widthplot = self.WIDTH + self.WIDTHPROF,
705 heightplot = self.HEIGHT + self.HEIGHTPROF,
705 heightplot = self.HEIGHT + self.HEIGHTPROF,
706 show=True)
706 show=True)
707
707
708 nrow, ncol = self.getSubplots()
708 nrow, ncol = self.getSubplots()
709
709
710 for y in range(nrow):
710 for y in range(nrow):
711 for x in range(ncol):
711 for x in range(ncol):
712
712
713 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
713 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
714
714
715 if showprofile:
715 if showprofile:
716 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
716 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
717
717
718 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
718 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
719 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
719 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
720 timerange=None, phase_min=None, phase_max=None,
720 timerange=None, phase_min=None, phase_max=None,
721 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
721 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
722 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
722 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
723 server=None, folder=None, username=None, password=None,
723 server=None, folder=None, username=None, password=None,
724 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
724 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
725
725
726 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
726 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
727 return
727 return
728
728
729 if pairsList == None:
729 if pairsList == None:
730 pairsIndexList = dataOut.pairsIndexList
730 pairsIndexList = dataOut.pairsIndexList
731 else:
731 else:
732 pairsIndexList = []
732 pairsIndexList = []
733 for pair in pairsList:
733 for pair in pairsList:
734 if pair not in dataOut.pairsList:
734 if pair not in dataOut.pairsList:
735 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
735 raise ValueError("Pair %s is not in dataOut.pairsList" %(pair))
736 pairsIndexList.append(dataOut.pairsList.index(pair))
736 pairsIndexList.append(dataOut.pairsList.index(pair))
737
737
738 if pairsIndexList == []:
738 if pairsIndexList == []:
739 return
739 return
740
740
741 if len(pairsIndexList) > 4:
741 if len(pairsIndexList) > 4:
742 pairsIndexList = pairsIndexList[0:4]
742 pairsIndexList = pairsIndexList[0:4]
743
743
744 if phase_min == None:
744 if phase_min == None:
745 phase_min = -180
745 phase_min = -180
746 if phase_max == None:
746 if phase_max == None:
747 phase_max = 180
747 phase_max = 180
748
748
749 x = dataOut.getTimeRange()
749 x = dataOut.getTimeRange()
750 y = dataOut.getHeiRange()
750 y = dataOut.getHeiRange()
751
751
752 thisDatetime = dataOut.datatime
752 thisDatetime = dataOut.datatime
753
753
754 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
754 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
755 xlabel = ""
755 xlabel = ""
756 ylabel = "Range (Km)"
756 ylabel = "Range (Km)"
757 update_figfile = False
757 update_figfile = False
758
758
759 if not self.isConfig:
759 if not self.isConfig:
760 nplots = len(pairsIndexList)
760 nplots = len(pairsIndexList)
761 self.setup(id=id,
761 self.setup(id=id,
762 nplots=nplots,
762 nplots=nplots,
763 wintitle=wintitle,
763 wintitle=wintitle,
764 showprofile=showprofile,
764 showprofile=showprofile,
765 show=show)
765 show=show)
766
766
767 if timerange != None:
767 if timerange != None:
768 self.timerange = timerange
768 self.timerange = timerange
769
769
770 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
770 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
771
771
772 if ymin == None: ymin = numpy.nanmin(y)
772 if ymin == None: ymin = numpy.nanmin(y)
773 if ymax == None: ymax = numpy.nanmax(y)
773 if ymax == None: ymax = numpy.nanmax(y)
774 if zmin == None: zmin = 0.
774 if zmin == None: zmin = 0.
775 if zmax == None: zmax = 1.
775 if zmax == None: zmax = 1.
776
776
777 self.FTP_WEI = ftp_wei
777 self.FTP_WEI = ftp_wei
778 self.EXP_CODE = exp_code
778 self.EXP_CODE = exp_code
779 self.SUB_EXP_CODE = sub_exp_code
779 self.SUB_EXP_CODE = sub_exp_code
780 self.PLOT_POS = plot_pos
780 self.PLOT_POS = plot_pos
781
781
782 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
782 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
783
783
784 self.isConfig = True
784 self.isConfig = True
785 update_figfile = True
785 update_figfile = True
786
786
787 self.setWinTitle(title)
787 self.setWinTitle(title)
788
788
789 for i in range(self.nplots):
789 for i in range(self.nplots):
790
790
791 pair = dataOut.pairsList[pairsIndexList[i]]
791 pair = dataOut.pairsList[pairsIndexList[i]]
792
792
793 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
793 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
794 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
794 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
795 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
795 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
796
796
797
797
798 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
798 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
799 coherence = numpy.abs(avgcoherenceComplex)
799 coherence = numpy.abs(avgcoherenceComplex)
800
800
801 z = coherence.reshape((1,-1))
801 z = coherence.reshape((1,-1))
802
802
803 counter = 0
803 counter = 0
804
804
805 title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
805 title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
806 axes = self.axesList[i*self.__nsubplots*2]
806 axes = self.axesList[i*self.__nsubplots*2]
807 axes.pcolorbuffer(x, y, z,
807 axes.pcolorbuffer(x, y, z,
808 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
808 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
809 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
809 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
810 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
810 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
811
811
812 if self.__showprofile:
812 if self.__showprofile:
813 counter += 1
813 counter += 1
814 axes = self.axesList[i*self.__nsubplots*2 + counter]
814 axes = self.axesList[i*self.__nsubplots*2 + counter]
815 axes.pline(coherence, y,
815 axes.pline(coherence, y,
816 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
816 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
817 xlabel='', ylabel='', title='', ticksize=7,
817 xlabel='', ylabel='', title='', ticksize=7,
818 ytick_visible=False, nxticks=5,
818 ytick_visible=False, nxticks=5,
819 grid='x')
819 grid='x')
820
820
821 counter += 1
821 counter += 1
822
822
823 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
823 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
824
824
825 z = phase.reshape((1,-1))
825 z = phase.reshape((1,-1))
826
826
827 title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
827 title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
828 axes = self.axesList[i*self.__nsubplots*2 + counter]
828 axes = self.axesList[i*self.__nsubplots*2 + counter]
829 axes.pcolorbuffer(x, y, z,
829 axes.pcolorbuffer(x, y, z,
830 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
830 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
831 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
831 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
832 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
832 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
833
833
834 if self.__showprofile:
834 if self.__showprofile:
835 counter += 1
835 counter += 1
836 axes = self.axesList[i*self.__nsubplots*2 + counter]
836 axes = self.axesList[i*self.__nsubplots*2 + counter]
837 axes.pline(phase, y,
837 axes.pline(phase, y,
838 xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax,
838 xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax,
839 xlabel='', ylabel='', title='', ticksize=7,
839 xlabel='', ylabel='', title='', ticksize=7,
840 ytick_visible=False, nxticks=4,
840 ytick_visible=False, nxticks=4,
841 grid='x')
841 grid='x')
842
842
843 self.draw()
843 self.draw()
844
844
845 if dataOut.ltctime >= self.xmax:
845 if dataOut.ltctime >= self.xmax:
846 self.counter_imagwr = wr_period
846 self.counter_imagwr = wr_period
847 self.isConfig = False
847 self.isConfig = False
848 update_figfile = True
848 update_figfile = True
849
849
850 self.save(figpath=figpath,
850 self.save(figpath=figpath,
851 figfile=figfile,
851 figfile=figfile,
852 save=save,
852 save=save,
853 ftp=ftp,
853 ftp=ftp,
854 wr_period=wr_period,
854 wr_period=wr_period,
855 thisDatetime=thisDatetime,
855 thisDatetime=thisDatetime,
856 update_figfile=update_figfile)
856 update_figfile=update_figfile)
857
857
858 class PowerProfilePlot(Figure):
858 class PowerProfilePlot(Figure):
859
859
860 isConfig = None
860 isConfig = None
861 __nsubplots = None
861 __nsubplots = None
862
862
863 WIDTHPROF = None
863 WIDTHPROF = None
864 HEIGHTPROF = None
864 HEIGHTPROF = None
865 PREFIX = 'spcprofile'
865 PREFIX = 'spcprofile'
866
866
867 def __init__(self, **kwargs):
867 def __init__(self, **kwargs):
868 Figure.__init__(self, **kwargs)
868 Figure.__init__(self, **kwargs)
869 self.isConfig = False
869 self.isConfig = False
870 self.__nsubplots = 1
870 self.__nsubplots = 1
871
871
872 self.PLOT_CODE = POWER_CODE
872 self.PLOT_CODE = POWER_CODE
873
873
874 self.WIDTH = 300
874 self.WIDTH = 300
875 self.HEIGHT = 500
875 self.HEIGHT = 500
876 self.counter_imagwr = 0
876 self.counter_imagwr = 0
877
877
878 def getSubplots(self):
878 def getSubplots(self):
879 ncol = 1
879 ncol = 1
880 nrow = 1
880 nrow = 1
881
881
882 return nrow, ncol
882 return nrow, ncol
883
883
884 def setup(self, id, nplots, wintitle, show):
884 def setup(self, id, nplots, wintitle, show):
885
885
886 self.nplots = nplots
886 self.nplots = nplots
887
887
888 ncolspan = 1
888 ncolspan = 1
889 colspan = 1
889 colspan = 1
890
890
891 self.createFigure(id = id,
891 self.createFigure(id = id,
892 wintitle = wintitle,
892 wintitle = wintitle,
893 widthplot = self.WIDTH,
893 widthplot = self.WIDTH,
894 heightplot = self.HEIGHT,
894 heightplot = self.HEIGHT,
895 show=show)
895 show=show)
896
896
897 nrow, ncol = self.getSubplots()
897 nrow, ncol = self.getSubplots()
898
898
899 counter = 0
899 counter = 0
900 for y in range(nrow):
900 for y in range(nrow):
901 for x in range(ncol):
901 for x in range(ncol):
902 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
902 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
903
903
904 def run(self, dataOut, id, wintitle="", channelList=None,
904 def run(self, dataOut, id, wintitle="", channelList=None,
905 xmin=None, xmax=None, ymin=None, ymax=None,
905 xmin=None, xmax=None, ymin=None, ymax=None,
906 save=False, figpath='./', figfile=None, show=True,
906 save=False, figpath='./', figfile=None, show=True,
907 ftp=False, wr_period=1, server=None,
907 ftp=False, wr_period=1, server=None,
908 folder=None, username=None, password=None):
908 folder=None, username=None, password=None):
909
909
910
910
911 if channelList == None:
911 if channelList == None:
912 channelIndexList = dataOut.channelIndexList
912 channelIndexList = dataOut.channelIndexList
913 channelList = dataOut.channelList
913 channelList = dataOut.channelList
914 else:
914 else:
915 channelIndexList = []
915 channelIndexList = []
916 for channel in channelList:
916 for channel in channelList:
917 if channel not in dataOut.channelList:
917 if channel not in dataOut.channelList:
918 raise ValueError, "Channel %d is not in dataOut.channelList"
918 raise ValueError("Channel %d is not in dataOut.channelList")
919 channelIndexList.append(dataOut.channelList.index(channel))
919 channelIndexList.append(dataOut.channelList.index(channel))
920
920
921 factor = dataOut.normFactor
921 factor = dataOut.normFactor
922
922
923 y = dataOut.getHeiRange()
923 y = dataOut.getHeiRange()
924
924
925 #for voltage
925 #for voltage
926 if dataOut.type == 'Voltage':
926 if dataOut.type == 'Voltage':
927 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
927 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
928 x = x.real
928 x = x.real
929 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
929 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
930
930
931 #for spectra
931 #for spectra
932 if dataOut.type == 'Spectra':
932 if dataOut.type == 'Spectra':
933 x = dataOut.data_spc[channelIndexList,:,:]/factor
933 x = dataOut.data_spc[channelIndexList,:,:]/factor
934 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
934 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
935 x = numpy.average(x, axis=1)
935 x = numpy.average(x, axis=1)
936
936
937
937
938 xdB = 10*numpy.log10(x)
938 xdB = 10*numpy.log10(x)
939
939
940 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
940 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
941 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
941 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
942 xlabel = "dB"
942 xlabel = "dB"
943 ylabel = "Range (Km)"
943 ylabel = "Range (Km)"
944
944
945 if not self.isConfig:
945 if not self.isConfig:
946
946
947 nplots = 1
947 nplots = 1
948
948
949 self.setup(id=id,
949 self.setup(id=id,
950 nplots=nplots,
950 nplots=nplots,
951 wintitle=wintitle,
951 wintitle=wintitle,
952 show=show)
952 show=show)
953
953
954 if ymin == None: ymin = numpy.nanmin(y)
954 if ymin == None: ymin = numpy.nanmin(y)
955 if ymax == None: ymax = numpy.nanmax(y)
955 if ymax == None: ymax = numpy.nanmax(y)
956 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
956 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
957 if xmax == None: xmax = numpy.nanmax(xdB)*1.1
957 if xmax == None: xmax = numpy.nanmax(xdB)*1.1
958
958
959 self.isConfig = True
959 self.isConfig = True
960
960
961 self.setWinTitle(title)
961 self.setWinTitle(title)
962
962
963 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
963 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
964 axes = self.axesList[0]
964 axes = self.axesList[0]
965
965
966 legendlabels = ["channel %d"%x for x in channelList]
966 legendlabels = ["channel %d"%x for x in channelList]
967 axes.pmultiline(xdB, y,
967 axes.pmultiline(xdB, y,
968 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
968 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
969 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
969 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
970 ytick_visible=True, nxticks=5,
970 ytick_visible=True, nxticks=5,
971 grid='x')
971 grid='x')
972
972
973 self.draw()
973 self.draw()
974
974
975 self.save(figpath=figpath,
975 self.save(figpath=figpath,
976 figfile=figfile,
976 figfile=figfile,
977 save=save,
977 save=save,
978 ftp=ftp,
978 ftp=ftp,
979 wr_period=wr_period,
979 wr_period=wr_period,
980 thisDatetime=thisDatetime)
980 thisDatetime=thisDatetime)
981
981
982 class SpectraCutPlot(Figure):
982 class SpectraCutPlot(Figure):
983
983
984 isConfig = None
984 isConfig = None
985 __nsubplots = None
985 __nsubplots = None
986
986
987 WIDTHPROF = None
987 WIDTHPROF = None
988 HEIGHTPROF = None
988 HEIGHTPROF = None
989 PREFIX = 'spc_cut'
989 PREFIX = 'spc_cut'
990
990
991 def __init__(self, **kwargs):
991 def __init__(self, **kwargs):
992 Figure.__init__(self, **kwargs)
992 Figure.__init__(self, **kwargs)
993 self.isConfig = False
993 self.isConfig = False
994 self.__nsubplots = 1
994 self.__nsubplots = 1
995
995
996 self.PLOT_CODE = POWER_CODE
996 self.PLOT_CODE = POWER_CODE
997
997
998 self.WIDTH = 700
998 self.WIDTH = 700
999 self.HEIGHT = 500
999 self.HEIGHT = 500
1000 self.counter_imagwr = 0
1000 self.counter_imagwr = 0
1001
1001
1002 def getSubplots(self):
1002 def getSubplots(self):
1003 ncol = 1
1003 ncol = 1
1004 nrow = 1
1004 nrow = 1
1005
1005
1006 return nrow, ncol
1006 return nrow, ncol
1007
1007
1008 def setup(self, id, nplots, wintitle, show):
1008 def setup(self, id, nplots, wintitle, show):
1009
1009
1010 self.nplots = nplots
1010 self.nplots = nplots
1011
1011
1012 ncolspan = 1
1012 ncolspan = 1
1013 colspan = 1
1013 colspan = 1
1014
1014
1015 self.createFigure(id = id,
1015 self.createFigure(id = id,
1016 wintitle = wintitle,
1016 wintitle = wintitle,
1017 widthplot = self.WIDTH,
1017 widthplot = self.WIDTH,
1018 heightplot = self.HEIGHT,
1018 heightplot = self.HEIGHT,
1019 show=show)
1019 show=show)
1020
1020
1021 nrow, ncol = self.getSubplots()
1021 nrow, ncol = self.getSubplots()
1022
1022
1023 counter = 0
1023 counter = 0
1024 for y in range(nrow):
1024 for y in range(nrow):
1025 for x in range(ncol):
1025 for x in range(ncol):
1026 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1026 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1027
1027
1028 def run(self, dataOut, id, wintitle="", channelList=None,
1028 def run(self, dataOut, id, wintitle="", channelList=None,
1029 xmin=None, xmax=None, ymin=None, ymax=None,
1029 xmin=None, xmax=None, ymin=None, ymax=None,
1030 save=False, figpath='./', figfile=None, show=True,
1030 save=False, figpath='./', figfile=None, show=True,
1031 ftp=False, wr_period=1, server=None,
1031 ftp=False, wr_period=1, server=None,
1032 folder=None, username=None, password=None,
1032 folder=None, username=None, password=None,
1033 xaxis="frequency"):
1033 xaxis="frequency"):
1034
1034
1035
1035
1036 if channelList == None:
1036 if channelList == None:
1037 channelIndexList = dataOut.channelIndexList
1037 channelIndexList = dataOut.channelIndexList
1038 channelList = dataOut.channelList
1038 channelList = dataOut.channelList
1039 else:
1039 else:
1040 channelIndexList = []
1040 channelIndexList = []
1041 for channel in channelList:
1041 for channel in channelList:
1042 if channel not in dataOut.channelList:
1042 if channel not in dataOut.channelList:
1043 raise ValueError, "Channel %d is not in dataOut.channelList"
1043 raise ValueError("Channel %d is not in dataOut.channelList")
1044 channelIndexList.append(dataOut.channelList.index(channel))
1044 channelIndexList.append(dataOut.channelList.index(channel))
1045
1045
1046 factor = dataOut.normFactor
1046 factor = dataOut.normFactor
1047
1047
1048 y = dataOut.getHeiRange()
1048 y = dataOut.getHeiRange()
1049
1049
1050 z = dataOut.data_spc/factor
1050 z = dataOut.data_spc/factor
1051 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1051 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1052
1052
1053 hei_index = numpy.arange(25)*3 + 20
1053 hei_index = numpy.arange(25)*3 + 20
1054
1054
1055 if xaxis == "frequency":
1055 if xaxis == "frequency":
1056 x = dataOut.getFreqRange()/1000.
1056 x = dataOut.getFreqRange()/1000.
1057 zdB = 10*numpy.log10(z[0,:,hei_index])
1057 zdB = 10*numpy.log10(z[0,:,hei_index])
1058 xlabel = "Frequency (kHz)"
1058 xlabel = "Frequency (kHz)"
1059 ylabel = "Power (dB)"
1059 ylabel = "Power (dB)"
1060
1060
1061 elif xaxis == "time":
1061 elif xaxis == "time":
1062 x = dataOut.getAcfRange()
1062 x = dataOut.getAcfRange()
1063 zdB = z[0,:,hei_index]
1063 zdB = z[0,:,hei_index]
1064 xlabel = "Time (ms)"
1064 xlabel = "Time (ms)"
1065 ylabel = "ACF"
1065 ylabel = "ACF"
1066
1066
1067 else:
1067 else:
1068 x = dataOut.getVelRange()
1068 x = dataOut.getVelRange()
1069 zdB = 10*numpy.log10(z[0,:,hei_index])
1069 zdB = 10*numpy.log10(z[0,:,hei_index])
1070 xlabel = "Velocity (m/s)"
1070 xlabel = "Velocity (m/s)"
1071 ylabel = "Power (dB)"
1071 ylabel = "Power (dB)"
1072
1072
1073 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1073 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1074 title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y"))
1074 title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y"))
1075
1075
1076 if not self.isConfig:
1076 if not self.isConfig:
1077
1077
1078 nplots = 1
1078 nplots = 1
1079
1079
1080 self.setup(id=id,
1080 self.setup(id=id,
1081 nplots=nplots,
1081 nplots=nplots,
1082 wintitle=wintitle,
1082 wintitle=wintitle,
1083 show=show)
1083 show=show)
1084
1084
1085 if xmin == None: xmin = numpy.nanmin(x)*0.9
1085 if xmin == None: xmin = numpy.nanmin(x)*0.9
1086 if xmax == None: xmax = numpy.nanmax(x)*1.1
1086 if xmax == None: xmax = numpy.nanmax(x)*1.1
1087 if ymin == None: ymin = numpy.nanmin(zdB)
1087 if ymin == None: ymin = numpy.nanmin(zdB)
1088 if ymax == None: ymax = numpy.nanmax(zdB)
1088 if ymax == None: ymax = numpy.nanmax(zdB)
1089
1089
1090 self.isConfig = True
1090 self.isConfig = True
1091
1091
1092 self.setWinTitle(title)
1092 self.setWinTitle(title)
1093
1093
1094 title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1094 title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1095 axes = self.axesList[0]
1095 axes = self.axesList[0]
1096
1096
1097 legendlabels = ["Range = %dKm" %y[i] for i in hei_index]
1097 legendlabels = ["Range = %dKm" %y[i] for i in hei_index]
1098
1098
1099 axes.pmultilineyaxis( x, zdB,
1099 axes.pmultilineyaxis( x, zdB,
1100 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1100 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1101 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1101 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1102 ytick_visible=True, nxticks=5,
1102 ytick_visible=True, nxticks=5,
1103 grid='x')
1103 grid='x')
1104
1104
1105 self.draw()
1105 self.draw()
1106
1106
1107 self.save(figpath=figpath,
1107 self.save(figpath=figpath,
1108 figfile=figfile,
1108 figfile=figfile,
1109 save=save,
1109 save=save,
1110 ftp=ftp,
1110 ftp=ftp,
1111 wr_period=wr_period,
1111 wr_period=wr_period,
1112 thisDatetime=thisDatetime)
1112 thisDatetime=thisDatetime)
1113
1113
1114 class Noise(Figure):
1114 class Noise(Figure):
1115
1115
1116 isConfig = None
1116 isConfig = None
1117 __nsubplots = None
1117 __nsubplots = None
1118
1118
1119 PREFIX = 'noise'
1119 PREFIX = 'noise'
1120
1120
1121
1121
1122 def __init__(self, **kwargs):
1122 def __init__(self, **kwargs):
1123 Figure.__init__(self, **kwargs)
1123 Figure.__init__(self, **kwargs)
1124 self.timerange = 24*60*60
1124 self.timerange = 24*60*60
1125 self.isConfig = False
1125 self.isConfig = False
1126 self.__nsubplots = 1
1126 self.__nsubplots = 1
1127 self.counter_imagwr = 0
1127 self.counter_imagwr = 0
1128 self.WIDTH = 800
1128 self.WIDTH = 800
1129 self.HEIGHT = 400
1129 self.HEIGHT = 400
1130 self.WIDTHPROF = 120
1130 self.WIDTHPROF = 120
1131 self.HEIGHTPROF = 0
1131 self.HEIGHTPROF = 0
1132 self.xdata = None
1132 self.xdata = None
1133 self.ydata = None
1133 self.ydata = None
1134
1134
1135 self.PLOT_CODE = NOISE_CODE
1135 self.PLOT_CODE = NOISE_CODE
1136
1136
1137 self.FTP_WEI = None
1137 self.FTP_WEI = None
1138 self.EXP_CODE = None
1138 self.EXP_CODE = None
1139 self.SUB_EXP_CODE = None
1139 self.SUB_EXP_CODE = None
1140 self.PLOT_POS = None
1140 self.PLOT_POS = None
1141 self.figfile = None
1141 self.figfile = None
1142
1142
1143 self.xmin = None
1143 self.xmin = None
1144 self.xmax = None
1144 self.xmax = None
1145
1145
1146 def getSubplots(self):
1146 def getSubplots(self):
1147
1147
1148 ncol = 1
1148 ncol = 1
1149 nrow = 1
1149 nrow = 1
1150
1150
1151 return nrow, ncol
1151 return nrow, ncol
1152
1152
1153 def openfile(self, filename):
1153 def openfile(self, filename):
1154 dirname = os.path.dirname(filename)
1154 dirname = os.path.dirname(filename)
1155
1155
1156 if not os.path.exists(dirname):
1156 if not os.path.exists(dirname):
1157 os.mkdir(dirname)
1157 os.mkdir(dirname)
1158
1158
1159 f = open(filename,'w+')
1159 f = open(filename,'w+')
1160 f.write('\n\n')
1160 f.write('\n\n')
1161 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
1161 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
1162 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
1162 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
1163 f.close()
1163 f.close()
1164
1164
1165 def save_data(self, filename_phase, data, data_datetime):
1165 def save_data(self, filename_phase, data, data_datetime):
1166
1166
1167 f=open(filename_phase,'a')
1167 f=open(filename_phase,'a')
1168
1168
1169 timetuple_data = data_datetime.timetuple()
1169 timetuple_data = data_datetime.timetuple()
1170 day = str(timetuple_data.tm_mday)
1170 day = str(timetuple_data.tm_mday)
1171 month = str(timetuple_data.tm_mon)
1171 month = str(timetuple_data.tm_mon)
1172 year = str(timetuple_data.tm_year)
1172 year = str(timetuple_data.tm_year)
1173 hour = str(timetuple_data.tm_hour)
1173 hour = str(timetuple_data.tm_hour)
1174 minute = str(timetuple_data.tm_min)
1174 minute = str(timetuple_data.tm_min)
1175 second = str(timetuple_data.tm_sec)
1175 second = str(timetuple_data.tm_sec)
1176
1176
1177 data_msg = ''
1177 data_msg = ''
1178 for i in range(len(data)):
1178 for i in range(len(data)):
1179 data_msg += str(data[i]) + ' '
1179 data_msg += str(data[i]) + ' '
1180
1180
1181 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n')
1181 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n')
1182 f.close()
1182 f.close()
1183
1183
1184
1184
1185 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1185 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1186
1186
1187 self.__showprofile = showprofile
1187 self.__showprofile = showprofile
1188 self.nplots = nplots
1188 self.nplots = nplots
1189
1189
1190 ncolspan = 7
1190 ncolspan = 7
1191 colspan = 6
1191 colspan = 6
1192 self.__nsubplots = 2
1192 self.__nsubplots = 2
1193
1193
1194 self.createFigure(id = id,
1194 self.createFigure(id = id,
1195 wintitle = wintitle,
1195 wintitle = wintitle,
1196 widthplot = self.WIDTH+self.WIDTHPROF,
1196 widthplot = self.WIDTH+self.WIDTHPROF,
1197 heightplot = self.HEIGHT+self.HEIGHTPROF,
1197 heightplot = self.HEIGHT+self.HEIGHTPROF,
1198 show=show)
1198 show=show)
1199
1199
1200 nrow, ncol = self.getSubplots()
1200 nrow, ncol = self.getSubplots()
1201
1201
1202 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1202 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1203
1203
1204
1204
1205 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1205 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1206 xmin=None, xmax=None, ymin=None, ymax=None,
1206 xmin=None, xmax=None, ymin=None, ymax=None,
1207 timerange=None,
1207 timerange=None,
1208 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1208 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1209 server=None, folder=None, username=None, password=None,
1209 server=None, folder=None, username=None, password=None,
1210 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1210 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1211
1211
1212 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1212 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1213 return
1213 return
1214
1214
1215 if channelList == None:
1215 if channelList == None:
1216 channelIndexList = dataOut.channelIndexList
1216 channelIndexList = dataOut.channelIndexList
1217 channelList = dataOut.channelList
1217 channelList = dataOut.channelList
1218 else:
1218 else:
1219 channelIndexList = []
1219 channelIndexList = []
1220 for channel in channelList:
1220 for channel in channelList:
1221 if channel not in dataOut.channelList:
1221 if channel not in dataOut.channelList:
1222 raise ValueError, "Channel %d is not in dataOut.channelList"
1222 raise ValueError("Channel %d is not in dataOut.channelList")
1223 channelIndexList.append(dataOut.channelList.index(channel))
1223 channelIndexList.append(dataOut.channelList.index(channel))
1224
1224
1225 x = dataOut.getTimeRange()
1225 x = dataOut.getTimeRange()
1226 #y = dataOut.getHeiRange()
1226 #y = dataOut.getHeiRange()
1227 factor = dataOut.normFactor
1227 factor = dataOut.normFactor
1228 noise = dataOut.noise[channelIndexList]/factor
1228 noise = dataOut.noise[channelIndexList]/factor
1229 noisedB = 10*numpy.log10(noise)
1229 noisedB = 10*numpy.log10(noise)
1230
1230
1231 thisDatetime = dataOut.datatime
1231 thisDatetime = dataOut.datatime
1232
1232
1233 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1233 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1234 xlabel = ""
1234 xlabel = ""
1235 ylabel = "Intensity (dB)"
1235 ylabel = "Intensity (dB)"
1236 update_figfile = False
1236 update_figfile = False
1237
1237
1238 if not self.isConfig:
1238 if not self.isConfig:
1239
1239
1240 nplots = 1
1240 nplots = 1
1241
1241
1242 self.setup(id=id,
1242 self.setup(id=id,
1243 nplots=nplots,
1243 nplots=nplots,
1244 wintitle=wintitle,
1244 wintitle=wintitle,
1245 showprofile=showprofile,
1245 showprofile=showprofile,
1246 show=show)
1246 show=show)
1247
1247
1248 if timerange != None:
1248 if timerange != None:
1249 self.timerange = timerange
1249 self.timerange = timerange
1250
1250
1251 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1251 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1252
1252
1253 if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0
1253 if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0
1254 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1254 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1255
1255
1256 self.FTP_WEI = ftp_wei
1256 self.FTP_WEI = ftp_wei
1257 self.EXP_CODE = exp_code
1257 self.EXP_CODE = exp_code
1258 self.SUB_EXP_CODE = sub_exp_code
1258 self.SUB_EXP_CODE = sub_exp_code
1259 self.PLOT_POS = plot_pos
1259 self.PLOT_POS = plot_pos
1260
1260
1261
1261
1262 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1262 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1263 self.isConfig = True
1263 self.isConfig = True
1264 self.figfile = figfile
1264 self.figfile = figfile
1265 self.xdata = numpy.array([])
1265 self.xdata = numpy.array([])
1266 self.ydata = numpy.array([])
1266 self.ydata = numpy.array([])
1267
1267
1268 update_figfile = True
1268 update_figfile = True
1269
1269
1270 #open file beacon phase
1270 #open file beacon phase
1271 path = '%s%03d' %(self.PREFIX, self.id)
1271 path = '%s%03d' %(self.PREFIX, self.id)
1272 noise_file = os.path.join(path,'%s.txt'%self.name)
1272 noise_file = os.path.join(path,'%s.txt'%self.name)
1273 self.filename_noise = os.path.join(figpath,noise_file)
1273 self.filename_noise = os.path.join(figpath,noise_file)
1274
1274
1275 self.setWinTitle(title)
1275 self.setWinTitle(title)
1276
1276
1277 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1277 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1278
1278
1279 legendlabels = ["channel %d"%(idchannel) for idchannel in channelList]
1279 legendlabels = ["channel %d"%(idchannel) for idchannel in channelList]
1280 axes = self.axesList[0]
1280 axes = self.axesList[0]
1281
1281
1282 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1282 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1283
1283
1284 if len(self.ydata)==0:
1284 if len(self.ydata)==0:
1285 self.ydata = noisedB.reshape(-1,1)
1285 self.ydata = noisedB.reshape(-1,1)
1286 else:
1286 else:
1287 self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1)))
1287 self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1)))
1288
1288
1289
1289
1290 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1290 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1291 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1291 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1292 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1292 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1293 XAxisAsTime=True, grid='both'
1293 XAxisAsTime=True, grid='both'
1294 )
1294 )
1295
1295
1296 self.draw()
1296 self.draw()
1297
1297
1298 if dataOut.ltctime >= self.xmax:
1298 if dataOut.ltctime >= self.xmax:
1299 self.counter_imagwr = wr_period
1299 self.counter_imagwr = wr_period
1300 self.isConfig = False
1300 self.isConfig = False
1301 update_figfile = True
1301 update_figfile = True
1302
1302
1303 self.save(figpath=figpath,
1303 self.save(figpath=figpath,
1304 figfile=figfile,
1304 figfile=figfile,
1305 save=save,
1305 save=save,
1306 ftp=ftp,
1306 ftp=ftp,
1307 wr_period=wr_period,
1307 wr_period=wr_period,
1308 thisDatetime=thisDatetime,
1308 thisDatetime=thisDatetime,
1309 update_figfile=update_figfile)
1309 update_figfile=update_figfile)
1310
1310
1311 #store data beacon phase
1311 #store data beacon phase
1312 if save:
1312 if save:
1313 self.save_data(self.filename_noise, noisedB, thisDatetime)
1313 self.save_data(self.filename_noise, noisedB, thisDatetime)
1314
1314
1315 class BeaconPhase(Figure):
1315 class BeaconPhase(Figure):
1316
1316
1317 __isConfig = None
1317 __isConfig = None
1318 __nsubplots = None
1318 __nsubplots = None
1319
1319
1320 PREFIX = 'beacon_phase'
1320 PREFIX = 'beacon_phase'
1321
1321
1322 def __init__(self, **kwargs):
1322 def __init__(self, **kwargs):
1323 Figure.__init__(self, **kwargs)
1323 Figure.__init__(self, **kwargs)
1324 self.timerange = 24*60*60
1324 self.timerange = 24*60*60
1325 self.isConfig = False
1325 self.isConfig = False
1326 self.__nsubplots = 1
1326 self.__nsubplots = 1
1327 self.counter_imagwr = 0
1327 self.counter_imagwr = 0
1328 self.WIDTH = 800
1328 self.WIDTH = 800
1329 self.HEIGHT = 400
1329 self.HEIGHT = 400
1330 self.WIDTHPROF = 120
1330 self.WIDTHPROF = 120
1331 self.HEIGHTPROF = 0
1331 self.HEIGHTPROF = 0
1332 self.xdata = None
1332 self.xdata = None
1333 self.ydata = None
1333 self.ydata = None
1334
1334
1335 self.PLOT_CODE = BEACON_CODE
1335 self.PLOT_CODE = BEACON_CODE
1336
1336
1337 self.FTP_WEI = None
1337 self.FTP_WEI = None
1338 self.EXP_CODE = None
1338 self.EXP_CODE = None
1339 self.SUB_EXP_CODE = None
1339 self.SUB_EXP_CODE = None
1340 self.PLOT_POS = None
1340 self.PLOT_POS = None
1341
1341
1342 self.filename_phase = None
1342 self.filename_phase = None
1343
1343
1344 self.figfile = None
1344 self.figfile = None
1345
1345
1346 self.xmin = None
1346 self.xmin = None
1347 self.xmax = None
1347 self.xmax = None
1348
1348
1349 def getSubplots(self):
1349 def getSubplots(self):
1350
1350
1351 ncol = 1
1351 ncol = 1
1352 nrow = 1
1352 nrow = 1
1353
1353
1354 return nrow, ncol
1354 return nrow, ncol
1355
1355
1356 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1356 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1357
1357
1358 self.__showprofile = showprofile
1358 self.__showprofile = showprofile
1359 self.nplots = nplots
1359 self.nplots = nplots
1360
1360
1361 ncolspan = 7
1361 ncolspan = 7
1362 colspan = 6
1362 colspan = 6
1363 self.__nsubplots = 2
1363 self.__nsubplots = 2
1364
1364
1365 self.createFigure(id = id,
1365 self.createFigure(id = id,
1366 wintitle = wintitle,
1366 wintitle = wintitle,
1367 widthplot = self.WIDTH+self.WIDTHPROF,
1367 widthplot = self.WIDTH+self.WIDTHPROF,
1368 heightplot = self.HEIGHT+self.HEIGHTPROF,
1368 heightplot = self.HEIGHT+self.HEIGHTPROF,
1369 show=show)
1369 show=show)
1370
1370
1371 nrow, ncol = self.getSubplots()
1371 nrow, ncol = self.getSubplots()
1372
1372
1373 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1373 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1374
1374
1375 def save_phase(self, filename_phase):
1375 def save_phase(self, filename_phase):
1376 f = open(filename_phase,'w+')
1376 f = open(filename_phase,'w+')
1377 f.write('\n\n')
1377 f.write('\n\n')
1378 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1378 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1379 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1379 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1380 f.close()
1380 f.close()
1381
1381
1382 def save_data(self, filename_phase, data, data_datetime):
1382 def save_data(self, filename_phase, data, data_datetime):
1383 f=open(filename_phase,'a')
1383 f=open(filename_phase,'a')
1384 timetuple_data = data_datetime.timetuple()
1384 timetuple_data = data_datetime.timetuple()
1385 day = str(timetuple_data.tm_mday)
1385 day = str(timetuple_data.tm_mday)
1386 month = str(timetuple_data.tm_mon)
1386 month = str(timetuple_data.tm_mon)
1387 year = str(timetuple_data.tm_year)
1387 year = str(timetuple_data.tm_year)
1388 hour = str(timetuple_data.tm_hour)
1388 hour = str(timetuple_data.tm_hour)
1389 minute = str(timetuple_data.tm_min)
1389 minute = str(timetuple_data.tm_min)
1390 second = str(timetuple_data.tm_sec)
1390 second = str(timetuple_data.tm_sec)
1391 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1391 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1392 f.close()
1392 f.close()
1393
1393
1394
1394
1395 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1395 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1396 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
1396 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
1397 timerange=None,
1397 timerange=None,
1398 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1398 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1399 server=None, folder=None, username=None, password=None,
1399 server=None, folder=None, username=None, password=None,
1400 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1400 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1401
1401
1402 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1402 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1403 return
1403 return
1404
1404
1405 if pairsList == None:
1405 if pairsList == None:
1406 pairsIndexList = dataOut.pairsIndexList[:10]
1406 pairsIndexList = dataOut.pairsIndexList[:10]
1407 else:
1407 else:
1408 pairsIndexList = []
1408 pairsIndexList = []
1409 for pair in pairsList:
1409 for pair in pairsList:
1410 if pair not in dataOut.pairsList:
1410 if pair not in dataOut.pairsList:
1411 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
1411 raise ValueError("Pair %s is not in dataOut.pairsList" %(pair))
1412 pairsIndexList.append(dataOut.pairsList.index(pair))
1412 pairsIndexList.append(dataOut.pairsList.index(pair))
1413
1413
1414 if pairsIndexList == []:
1414 if pairsIndexList == []:
1415 return
1415 return
1416
1416
1417 # if len(pairsIndexList) > 4:
1417 # if len(pairsIndexList) > 4:
1418 # pairsIndexList = pairsIndexList[0:4]
1418 # pairsIndexList = pairsIndexList[0:4]
1419
1419
1420 hmin_index = None
1420 hmin_index = None
1421 hmax_index = None
1421 hmax_index = None
1422
1422
1423 if hmin != None and hmax != None:
1423 if hmin != None and hmax != None:
1424 indexes = numpy.arange(dataOut.nHeights)
1424 indexes = numpy.arange(dataOut.nHeights)
1425 hmin_list = indexes[dataOut.heightList >= hmin]
1425 hmin_list = indexes[dataOut.heightList >= hmin]
1426 hmax_list = indexes[dataOut.heightList <= hmax]
1426 hmax_list = indexes[dataOut.heightList <= hmax]
1427
1427
1428 if hmin_list.any():
1428 if hmin_list.any():
1429 hmin_index = hmin_list[0]
1429 hmin_index = hmin_list[0]
1430
1430
1431 if hmax_list.any():
1431 if hmax_list.any():
1432 hmax_index = hmax_list[-1]+1
1432 hmax_index = hmax_list[-1]+1
1433
1433
1434 x = dataOut.getTimeRange()
1434 x = dataOut.getTimeRange()
1435 #y = dataOut.getHeiRange()
1435 #y = dataOut.getHeiRange()
1436
1436
1437
1437
1438 thisDatetime = dataOut.datatime
1438 thisDatetime = dataOut.datatime
1439
1439
1440 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1440 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1441 xlabel = "Local Time"
1441 xlabel = "Local Time"
1442 ylabel = "Phase (degrees)"
1442 ylabel = "Phase (degrees)"
1443
1443
1444 update_figfile = False
1444 update_figfile = False
1445
1445
1446 nplots = len(pairsIndexList)
1446 nplots = len(pairsIndexList)
1447 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1447 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1448 phase_beacon = numpy.zeros(len(pairsIndexList))
1448 phase_beacon = numpy.zeros(len(pairsIndexList))
1449 for i in range(nplots):
1449 for i in range(nplots):
1450 pair = dataOut.pairsList[pairsIndexList[i]]
1450 pair = dataOut.pairsList[pairsIndexList[i]]
1451 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
1451 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
1452 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
1452 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
1453 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
1453 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
1454 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1454 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1455 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1455 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1456
1456
1457 #print "Phase %d%d" %(pair[0], pair[1])
1457 #print "Phase %d%d" %(pair[0], pair[1])
1458 #print phase[dataOut.beacon_heiIndexList]
1458 #print phase[dataOut.beacon_heiIndexList]
1459
1459
1460 if dataOut.beacon_heiIndexList:
1460 if dataOut.beacon_heiIndexList:
1461 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1461 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1462 else:
1462 else:
1463 phase_beacon[i] = numpy.average(phase)
1463 phase_beacon[i] = numpy.average(phase)
1464
1464
1465 if not self.isConfig:
1465 if not self.isConfig:
1466
1466
1467 nplots = len(pairsIndexList)
1467 nplots = len(pairsIndexList)
1468
1468
1469 self.setup(id=id,
1469 self.setup(id=id,
1470 nplots=nplots,
1470 nplots=nplots,
1471 wintitle=wintitle,
1471 wintitle=wintitle,
1472 showprofile=showprofile,
1472 showprofile=showprofile,
1473 show=show)
1473 show=show)
1474
1474
1475 if timerange != None:
1475 if timerange != None:
1476 self.timerange = timerange
1476 self.timerange = timerange
1477
1477
1478 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1478 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1479
1479
1480 if ymin == None: ymin = 0
1480 if ymin == None: ymin = 0
1481 if ymax == None: ymax = 360
1481 if ymax == None: ymax = 360
1482
1482
1483 self.FTP_WEI = ftp_wei
1483 self.FTP_WEI = ftp_wei
1484 self.EXP_CODE = exp_code
1484 self.EXP_CODE = exp_code
1485 self.SUB_EXP_CODE = sub_exp_code
1485 self.SUB_EXP_CODE = sub_exp_code
1486 self.PLOT_POS = plot_pos
1486 self.PLOT_POS = plot_pos
1487
1487
1488 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1488 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1489 self.isConfig = True
1489 self.isConfig = True
1490 self.figfile = figfile
1490 self.figfile = figfile
1491 self.xdata = numpy.array([])
1491 self.xdata = numpy.array([])
1492 self.ydata = numpy.array([])
1492 self.ydata = numpy.array([])
1493
1493
1494 update_figfile = True
1494 update_figfile = True
1495
1495
1496 #open file beacon phase
1496 #open file beacon phase
1497 path = '%s%03d' %(self.PREFIX, self.id)
1497 path = '%s%03d' %(self.PREFIX, self.id)
1498 beacon_file = os.path.join(path,'%s.txt'%self.name)
1498 beacon_file = os.path.join(path,'%s.txt'%self.name)
1499 self.filename_phase = os.path.join(figpath,beacon_file)
1499 self.filename_phase = os.path.join(figpath,beacon_file)
1500 #self.save_phase(self.filename_phase)
1500 #self.save_phase(self.filename_phase)
1501
1501
1502
1502
1503 #store data beacon phase
1503 #store data beacon phase
1504 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1504 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1505
1505
1506 self.setWinTitle(title)
1506 self.setWinTitle(title)
1507
1507
1508
1508
1509 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1509 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1510
1510
1511 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1511 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1512
1512
1513 axes = self.axesList[0]
1513 axes = self.axesList[0]
1514
1514
1515 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1515 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1516
1516
1517 if len(self.ydata)==0:
1517 if len(self.ydata)==0:
1518 self.ydata = phase_beacon.reshape(-1,1)
1518 self.ydata = phase_beacon.reshape(-1,1)
1519 else:
1519 else:
1520 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1520 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1521
1521
1522
1522
1523 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1523 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1524 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1524 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1525 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1525 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1526 XAxisAsTime=True, grid='both'
1526 XAxisAsTime=True, grid='both'
1527 )
1527 )
1528
1528
1529 self.draw()
1529 self.draw()
1530
1530
1531 if dataOut.ltctime >= self.xmax:
1531 if dataOut.ltctime >= self.xmax:
1532 self.counter_imagwr = wr_period
1532 self.counter_imagwr = wr_period
1533 self.isConfig = False
1533 self.isConfig = False
1534 update_figfile = True
1534 update_figfile = True
1535
1535
1536 self.save(figpath=figpath,
1536 self.save(figpath=figpath,
1537 figfile=figfile,
1537 figfile=figfile,
1538 save=save,
1538 save=save,
1539 ftp=ftp,
1539 ftp=ftp,
1540 wr_period=wr_period,
1540 wr_period=wr_period,
1541 thisDatetime=thisDatetime,
1541 thisDatetime=thisDatetime,
1542 update_figfile=update_figfile)
1542 update_figfile=update_figfile) No newline at end of file
@@ -1,225 +1,225
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
10 from .figure import Figure
11
11
12 class Scope(Figure):
12 class Scope(Figure):
13
13
14 isConfig = None
14 isConfig = None
15
15
16 def __init__(self, **kwargs):
16 def __init__(self, **kwargs):
17 Figure.__init__(self, **kwargs)
17 Figure.__init__(self, **kwargs)
18 self.isConfig = False
18 self.isConfig = False
19 self.WIDTH = 300
19 self.WIDTH = 300
20 self.HEIGHT = 200
20 self.HEIGHT = 200
21 self.counter_imagwr = 0
21 self.counter_imagwr = 0
22
22
23 def getSubplots(self):
23 def getSubplots(self):
24
24
25 nrow = self.nplots
25 nrow = self.nplots
26 ncol = 3
26 ncol = 3
27 return nrow, ncol
27 return nrow, ncol
28
28
29 def setup(self, id, nplots, wintitle, show):
29 def setup(self, id, nplots, wintitle, show):
30
30
31 self.nplots = nplots
31 self.nplots = nplots
32
32
33 self.createFigure(id=id,
33 self.createFigure(id=id,
34 wintitle=wintitle,
34 wintitle=wintitle,
35 show=show)
35 show=show)
36
36
37 nrow,ncol = self.getSubplots()
37 nrow,ncol = self.getSubplots()
38 colspan = 3
38 colspan = 3
39 rowspan = 1
39 rowspan = 1
40
40
41 for i in range(nplots):
41 for i in range(nplots):
42 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
42 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
43
43
44 def plot_iq(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
44 def plot_iq(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
45 yreal = y[channelIndexList,:].real
45 yreal = y[channelIndexList,:].real
46 yimag = y[channelIndexList,:].imag
46 yimag = y[channelIndexList,:].imag
47
47
48 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
48 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
49 xlabel = "Range (Km)"
49 xlabel = "Range (Km)"
50 ylabel = "Intensity - IQ"
50 ylabel = "Intensity - IQ"
51
51
52 if not self.isConfig:
52 if not self.isConfig:
53 nplots = len(channelIndexList)
53 nplots = len(channelIndexList)
54
54
55 self.setup(id=id,
55 self.setup(id=id,
56 nplots=nplots,
56 nplots=nplots,
57 wintitle='',
57 wintitle='',
58 show=show)
58 show=show)
59
59
60 if xmin == None: xmin = numpy.nanmin(x)
60 if xmin == None: xmin = numpy.nanmin(x)
61 if xmax == None: xmax = numpy.nanmax(x)
61 if xmax == None: xmax = numpy.nanmax(x)
62 if ymin == None: ymin = min(numpy.nanmin(yreal),numpy.nanmin(yimag))
62 if ymin == None: ymin = min(numpy.nanmin(yreal),numpy.nanmin(yimag))
63 if ymax == None: ymax = max(numpy.nanmax(yreal),numpy.nanmax(yimag))
63 if ymax == None: ymax = max(numpy.nanmax(yreal),numpy.nanmax(yimag))
64
64
65 self.isConfig = True
65 self.isConfig = True
66
66
67 self.setWinTitle(title)
67 self.setWinTitle(title)
68
68
69 for i in range(len(self.axesList)):
69 for i in range(len(self.axesList)):
70 title = "Channel %d" %(i)
70 title = "Channel %d" %(i)
71 axes = self.axesList[i]
71 axes = self.axesList[i]
72
72
73 axes.pline(x, yreal[i,:],
73 axes.pline(x, yreal[i,:],
74 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
74 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
75 xlabel=xlabel, ylabel=ylabel, title=title)
75 xlabel=xlabel, ylabel=ylabel, title=title)
76
76
77 axes.addpline(x, yimag[i,:], idline=1, color="red", linestyle="solid", lw=2)
77 axes.addpline(x, yimag[i,:], idline=1, color="red", linestyle="solid", lw=2)
78
78
79 def plot_power(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
79 def plot_power(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
80 y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:])
80 y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:])
81 yreal = y.real
81 yreal = y.real
82
82
83 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
83 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
84 xlabel = "Range (Km)"
84 xlabel = "Range (Km)"
85 ylabel = "Intensity"
85 ylabel = "Intensity"
86
86
87 if not self.isConfig:
87 if not self.isConfig:
88 nplots = len(channelIndexList)
88 nplots = len(channelIndexList)
89
89
90 self.setup(id=id,
90 self.setup(id=id,
91 nplots=nplots,
91 nplots=nplots,
92 wintitle='',
92 wintitle='',
93 show=show)
93 show=show)
94
94
95 if xmin == None: xmin = numpy.nanmin(x)
95 if xmin == None: xmin = numpy.nanmin(x)
96 if xmax == None: xmax = numpy.nanmax(x)
96 if xmax == None: xmax = numpy.nanmax(x)
97 if ymin == None: ymin = numpy.nanmin(yreal)
97 if ymin == None: ymin = numpy.nanmin(yreal)
98 if ymax == None: ymax = numpy.nanmax(yreal)
98 if ymax == None: ymax = numpy.nanmax(yreal)
99
99
100 self.isConfig = True
100 self.isConfig = True
101
101
102 self.setWinTitle(title)
102 self.setWinTitle(title)
103
103
104 for i in range(len(self.axesList)):
104 for i in range(len(self.axesList)):
105 title = "Channel %d" %(i)
105 title = "Channel %d" %(i)
106 axes = self.axesList[i]
106 axes = self.axesList[i]
107 ychannel = yreal[i,:]
107 ychannel = yreal[i,:]
108 axes.pline(x, ychannel,
108 axes.pline(x, ychannel,
109 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
109 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
110 xlabel=xlabel, ylabel=ylabel, title=title)
110 xlabel=xlabel, ylabel=ylabel, title=title)
111
111
112
112
113 def run(self, dataOut, id, wintitle="", channelList=None,
113 def run(self, dataOut, id, wintitle="", channelList=None,
114 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
114 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
115 figpath='./', figfile=None, show=True, wr_period=1,
115 figpath='./', figfile=None, show=True, wr_period=1,
116 ftp=False, server=None, folder=None, username=None, password=None, type='power', **kwargs):
116 ftp=False, server=None, folder=None, username=None, password=None, type='power', **kwargs):
117
117
118 """
118 """
119
119
120 Input:
120 Input:
121 dataOut :
121 dataOut :
122 id :
122 id :
123 wintitle :
123 wintitle :
124 channelList :
124 channelList :
125 xmin : None,
125 xmin : None,
126 xmax : None,
126 xmax : None,
127 ymin : None,
127 ymin : None,
128 ymax : None,
128 ymax : None,
129 """
129 """
130
130
131 if channelList == None:
131 if channelList == None:
132 channelIndexList = dataOut.channelIndexList
132 channelIndexList = dataOut.channelIndexList
133 else:
133 else:
134 channelIndexList = []
134 channelIndexList = []
135 for channel in channelList:
135 for channel in channelList:
136 if channel not in dataOut.channelList:
136 if channel not in dataOut.channelList:
137 raise ValueError, "Channel %d is not in dataOut.channelList"
137 raise ValueError("Channel %d is not in dataOut.channelList")
138 channelIndexList.append(dataOut.channelList.index(channel))
138 channelIndexList.append(dataOut.channelList.index(channel))
139
139
140 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
140 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
141
141
142 if dataOut.flagDataAsBlock:
142 if dataOut.flagDataAsBlock:
143
143
144 for i in range(dataOut.nProfiles):
144 for i in range(dataOut.nProfiles):
145
145
146 wintitle1 = wintitle + " [Profile = %d] " %i
146 wintitle1 = wintitle + " [Profile = %d] " %i
147
147
148 if type == "power":
148 if type == "power":
149 self.plot_power(dataOut.heightList,
149 self.plot_power(dataOut.heightList,
150 dataOut.data[:,i,:],
150 dataOut.data[:,i,:],
151 id,
151 id,
152 channelIndexList,
152 channelIndexList,
153 thisDatetime,
153 thisDatetime,
154 wintitle1,
154 wintitle1,
155 show,
155 show,
156 xmin,
156 xmin,
157 xmax,
157 xmax,
158 ymin,
158 ymin,
159 ymax)
159 ymax)
160
160
161 if type == "iq":
161 if type == "iq":
162 self.plot_iq(dataOut.heightList,
162 self.plot_iq(dataOut.heightList,
163 dataOut.data[:,i,:],
163 dataOut.data[:,i,:],
164 id,
164 id,
165 channelIndexList,
165 channelIndexList,
166 thisDatetime,
166 thisDatetime,
167 wintitle1,
167 wintitle1,
168 show,
168 show,
169 xmin,
169 xmin,
170 xmax,
170 xmax,
171 ymin,
171 ymin,
172 ymax)
172 ymax)
173
173
174 self.draw()
174 self.draw()
175
175
176 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
176 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
177 figfile = self.getFilename(name = str_datetime) + "_" + str(i)
177 figfile = self.getFilename(name = str_datetime) + "_" + str(i)
178
178
179 self.save(figpath=figpath,
179 self.save(figpath=figpath,
180 figfile=figfile,
180 figfile=figfile,
181 save=save,
181 save=save,
182 ftp=ftp,
182 ftp=ftp,
183 wr_period=wr_period,
183 wr_period=wr_period,
184 thisDatetime=thisDatetime)
184 thisDatetime=thisDatetime)
185
185
186 else:
186 else:
187 wintitle += " [Profile = %d] " %dataOut.profileIndex
187 wintitle += " [Profile = %d] " %dataOut.profileIndex
188
188
189 if type == "power":
189 if type == "power":
190 self.plot_power(dataOut.heightList,
190 self.plot_power(dataOut.heightList,
191 dataOut.data,
191 dataOut.data,
192 id,
192 id,
193 channelIndexList,
193 channelIndexList,
194 thisDatetime,
194 thisDatetime,
195 wintitle,
195 wintitle,
196 show,
196 show,
197 xmin,
197 xmin,
198 xmax,
198 xmax,
199 ymin,
199 ymin,
200 ymax)
200 ymax)
201
201
202 if type == "iq":
202 if type == "iq":
203 self.plot_iq(dataOut.heightList,
203 self.plot_iq(dataOut.heightList,
204 dataOut.data,
204 dataOut.data,
205 id,
205 id,
206 channelIndexList,
206 channelIndexList,
207 thisDatetime,
207 thisDatetime,
208 wintitle,
208 wintitle,
209 show,
209 show,
210 xmin,
210 xmin,
211 xmax,
211 xmax,
212 ymin,
212 ymin,
213 ymax)
213 ymax)
214
214
215 self.draw()
215 self.draw()
216
216
217 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") + "_" + str(dataOut.profileIndex)
217 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") + "_" + str(dataOut.profileIndex)
218 figfile = self.getFilename(name = str_datetime)
218 figfile = self.getFilename(name = str_datetime)
219
219
220 self.save(figpath=figpath,
220 self.save(figpath=figpath,
221 figfile=figfile,
221 figfile=figfile,
222 save=save,
222 save=save,
223 ftp=ftp,
223 ftp=ftp,
224 wr_period=wr_period,
224 wr_period=wr_period,
225 thisDatetime=thisDatetime)
225 thisDatetime=thisDatetime) No newline at end of file
@@ -1,240 +1,240
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, sys
6 import os, sys
7 import datetime
7 import datetime
8 import numpy
8 import numpy
9 import traceback
9 import traceback
10
10
11 from time import sleep
11 from time import sleep
12 from threading import Lock
12 from threading import Lock
13 # from threading import Thread
13 # from threading import Thread
14
14
15 import schainpy
15 import schainpy
16 import schainpy.admin
16 import schainpy.admin
17
17
18 from schainpy.model.proc.jroproc_base import Operation
18 from schainpy.model.proc.jroproc_base import Operation
19 from schainpy.model.serializer.data import obj2Dict, dict2Obj
19 from schainpy.model.serializer.data import obj2Dict, dict2Obj
20 from jroplot_correlation import *
20 from .jroplot_correlation import *
21 from jroplot_heispectra import *
21 from .jroplot_heispectra import *
22 from jroplot_parameters import *
22 from .jroplot_parameters import *
23 from jroplot_spectra import *
23 from .jroplot_spectra import *
24 from jroplot_voltage import *
24 from .jroplot_voltage import *
25
25
26
26
27 class Plotter(Operation):
27 class Plotter(Operation):
28
28
29 isConfig = None
29 isConfig = None
30 name = None
30 name = None
31 __queue = None
31 __queue = None
32
32
33 def __init__(self, plotter_name, plotter_queue=None, **kwargs):
33 def __init__(self, plotter_name, plotter_queue=None, **kwargs):
34
34
35 Operation.__init__(self, **kwargs)
35 Operation.__init__(self, **kwargs)
36
36
37 self.isConfig = False
37 self.isConfig = False
38 self.name = plotter_name
38 self.name = plotter_name
39 self.__queue = plotter_queue
39 self.__queue = plotter_queue
40
40
41 def getSubplots(self):
41 def getSubplots(self):
42
42
43 nrow = self.nplots
43 nrow = self.nplots
44 ncol = 1
44 ncol = 1
45 return nrow, ncol
45 return nrow, ncol
46
46
47 def setup(self, **kwargs):
47 def setup(self, **kwargs):
48
48
49 print "Initializing ..."
49 print("Initializing ...")
50
50
51
51
52 def run(self, dataOut, id=None, **kwargs):
52 def run(self, dataOut, id=None, **kwargs):
53
53
54 """
54 """
55
55
56 Input:
56 Input:
57 dataOut :
57 dataOut :
58 id :
58 id :
59 """
59 """
60
60
61 packDict = {}
61 packDict = {}
62
62
63 packDict['id'] = id
63 packDict['id'] = id
64 packDict['name'] = self.name
64 packDict['name'] = self.name
65 packDict['kwargs'] = kwargs
65 packDict['kwargs'] = kwargs
66
66
67 # packDict['data'] = obj2Dict(dataOut)
67 # packDict['data'] = obj2Dict(dataOut)
68 packDict['data'] = dataOut
68 packDict['data'] = dataOut
69
69
70 self.__queue.put(packDict)
70 self.__queue.put(packDict)
71
71
72 # class PlotManager(Thread):
72 # class PlotManager(Thread):
73 class PlotManager():
73 class PlotManager():
74
74
75 __err = False
75 __err = False
76 __stop = False
76 __stop = False
77 __realtime = False
77 __realtime = False
78
78
79 controllerThreadObj = None
79 controllerThreadObj = None
80
80
81 plotterList = ['Scope',
81 plotterList = ['Scope',
82 'SpectraPlot', 'RTIPlot',
82 'SpectraPlot', 'RTIPlot',
83 'SpectraCutPlot',
83 'SpectraCutPlot',
84 'CrossSpectraPlot', 'CoherenceMap',
84 'CrossSpectraPlot', 'CoherenceMap',
85 'PowerProfilePlot', 'Noise', 'BeaconPhase',
85 'PowerProfilePlot', 'Noise', 'BeaconPhase',
86 'CorrelationPlot',
86 'CorrelationPlot',
87 'SpectraHeisScope', 'RTIfromSpectraHeis']
87 'SpectraHeisScope', 'RTIfromSpectraHeis']
88
88
89 def __init__(self, plotter_queue):
89 def __init__(self, plotter_queue):
90
90
91 # Thread.__init__(self)
91 # Thread.__init__(self)
92 # self.setDaemon(True)
92 # self.setDaemon(True)
93
93
94 self.__queue = plotter_queue
94 self.__queue = plotter_queue
95 self.__lock = Lock()
95 self.__lock = Lock()
96
96
97 self.plotInstanceDict = {}
97 self.plotInstanceDict = {}
98
98
99 self.__err = False
99 self.__err = False
100 self.__stop = False
100 self.__stop = False
101 self.__realtime = False
101 self.__realtime = False
102
102
103 def __handleError(self, name="", send_email=False):
103 def __handleError(self, name="", send_email=False):
104
104
105 err = traceback.format_exception(sys.exc_info()[0],
105 err = traceback.format_exception(sys.exc_info()[0],
106 sys.exc_info()[1],
106 sys.exc_info()[1],
107 sys.exc_info()[2])
107 sys.exc_info()[2])
108
108
109 print "***** Error occurred in PlotManager *****"
109 print("***** Error occurred in PlotManager *****")
110 print "***** [%s]: %s" %(name, err[-1])
110 print("***** [%s]: %s" %(name, err[-1]))
111
111
112 message = "\nError ocurred in %s:\n" %name
112 message = "\nError ocurred in %s:\n" %name
113 message += "".join(err)
113 message += "".join(err)
114
114
115 sys.stderr.write(message)
115 sys.stderr.write(message)
116
116
117 if not send_email:
117 if not send_email:
118 return
118 return
119
119
120 import socket
120 import socket
121
121
122 subject = "SChain v%s: Error running %s\n" %(schainpy.__version__, name)
122 subject = "SChain v%s: Error running %s\n" %(schainpy.__version__, name)
123
123
124 subtitle = "%s:\n" %(name)
124 subtitle = "%s:\n" %(name)
125 subtitle += "Hostname: %s\n" %socket.gethostbyname(socket.gethostname())
125 subtitle += "Hostname: %s\n" %socket.gethostbyname(socket.gethostname())
126 subtitle += "Working directory: %s\n" %os.path.abspath("./")
126 subtitle += "Working directory: %s\n" %os.path.abspath("./")
127 # subtitle += "Configuration file: %s\n" %self.filename
127 # subtitle += "Configuration file: %s\n" %self.filename
128 subtitle += "Time: %s\n" %str(datetime.datetime.now())
128 subtitle += "Time: %s\n" %str(datetime.datetime.now())
129
129
130 adminObj = schainpy.admin.SchainNotify()
130 adminObj = schainpy.admin.SchainNotify()
131 adminObj.sendAlert(message=message,
131 adminObj.sendAlert(message=message,
132 subject=subject,
132 subject=subject,
133 subtitle=subtitle)
133 subtitle=subtitle)
134
134
135 def run(self):
135 def run(self):
136
136
137 if self.__queue.empty():
137 if self.__queue.empty():
138 return
138 return
139
139
140 if self.__err:
140 if self.__err:
141 serial_data = self.__queue.get()
141 serial_data = self.__queue.get()
142 self.__queue.task_done()
142 self.__queue.task_done()
143 return
143 return
144
144
145 self.__lock.acquire()
145 self.__lock.acquire()
146
146
147 # if self.__queue.full():
147 # if self.__queue.full():
148 # for i in range(int(self.__queue.qsize()/2)):
148 # for i in range(int(self.__queue.qsize()/2)):
149 # serial_data = self.__queue.get()
149 # serial_data = self.__queue.get()
150 # self.__queue.task_done()
150 # self.__queue.task_done()
151
151
152 n = int(self.__queue.qsize()/3 + 1)
152 n = int(self.__queue.qsize()/3 + 1)
153
153
154 for i in range(n):
154 for i in range(n):
155
155
156 if self.__queue.empty():
156 if self.__queue.empty():
157 break
157 break
158
158
159 serial_data = self.__queue.get()
159 serial_data = self.__queue.get()
160 self.__queue.task_done()
160 self.__queue.task_done()
161
161
162 plot_id = serial_data['id']
162 plot_id = serial_data['id']
163 plot_name = serial_data['name']
163 plot_name = serial_data['name']
164 kwargs = serial_data['kwargs']
164 kwargs = serial_data['kwargs']
165 # dataDict = serial_data['data']
165 # dataDict = serial_data['data']
166 #
166 #
167 # dataPlot = dict2Obj(dataDict)
167 # dataPlot = dict2Obj(dataDict)
168
168
169 dataPlot = serial_data['data']
169 dataPlot = serial_data['data']
170
170
171 if plot_id not in self.plotInstanceDict.keys():
171 if plot_id not in list(self.plotInstanceDict.keys()):
172 className = eval(plot_name)
172 className = eval(plot_name)
173 self.plotInstanceDict[plot_id] = className(**kwargs)
173 self.plotInstanceDict[plot_id] = className(**kwargs)
174
174
175 plotter = self.plotInstanceDict[plot_id]
175 plotter = self.plotInstanceDict[plot_id]
176 try:
176 try:
177 plotter.run(dataPlot, plot_id, **kwargs)
177 plotter.run(dataPlot, plot_id, **kwargs)
178 except:
178 except:
179 self.__err = True
179 self.__err = True
180 self.__handleError(plot_name, send_email=True)
180 self.__handleError(plot_name, send_email=True)
181 break
181 break
182
182
183 self.__lock.release()
183 self.__lock.release()
184
184
185 def isEmpty(self):
185 def isEmpty(self):
186
186
187 return self.__queue.empty()
187 return self.__queue.empty()
188
188
189 def stop(self):
189 def stop(self):
190
190
191 self.__lock.acquire()
191 self.__lock.acquire()
192
192
193 self.__stop = True
193 self.__stop = True
194
194
195 self.__lock.release()
195 self.__lock.release()
196
196
197 def close(self):
197 def close(self):
198
198
199 self.__lock.acquire()
199 self.__lock.acquire()
200
200
201 for plot_id in self.plotInstanceDict.keys():
201 for plot_id in list(self.plotInstanceDict.keys()):
202 plotter = self.plotInstanceDict[plot_id]
202 plotter = self.plotInstanceDict[plot_id]
203 plotter.close()
203 plotter.close()
204
204
205 self.__lock.release()
205 self.__lock.release()
206
206
207 def setController(self, controllerThreadObj):
207 def setController(self, controllerThreadObj):
208
208
209 self.controllerThreadObj = controllerThreadObj
209 self.controllerThreadObj = controllerThreadObj
210
210
211 def start(self):
211 def start(self):
212
212
213 if not self.controllerThreadObj.isRunning():
213 if not self.controllerThreadObj.isRunning():
214 raise RuntimeError, "controllerThreadObj has not been initialized. Use controllerThreadObj.start() before call this method"
214 raise RuntimeError("controllerThreadObj has not been initialized. Use controllerThreadObj.start() before call this method")
215
215
216 self.join()
216 self.join()
217
217
218 def join(self):
218 def join(self):
219
219
220 #Execute plotter while controller is running
220 #Execute plotter while controller is running
221 while self.controllerThreadObj.isRunning():
221 while self.controllerThreadObj.isRunning():
222 self.run()
222 self.run()
223
223
224 self.controllerThreadObj.stop()
224 self.controllerThreadObj.stop()
225
225
226 #Wait until plotter queue is empty
226 #Wait until plotter queue is empty
227 while not self.isEmpty():
227 while not self.isEmpty():
228 self.run()
228 self.run()
229
229
230 self.close()
230 self.close()
231
231
232 def isErrorDetected(self):
232 def isErrorDetected(self):
233
233
234 self.__lock.acquire()
234 self.__lock.acquire()
235
235
236 err = self.__err
236 err = self.__err
237
237
238 self.__lock.release()
238 self.__lock.release()
239
239
240 return err
240 return err No newline at end of file
@@ -1,501 +1,501
1 import os
1 import os
2 import sys
2 import sys
3 import datetime
3 import datetime
4 import numpy
4 import numpy
5 import matplotlib
5 import matplotlib
6
6
7 if 'BACKEND' in os.environ:
7 if 'BACKEND' in os.environ:
8 matplotlib.use(os.environ['BACKEND'])
8 matplotlib.use(os.environ['BACKEND'])
9 elif 'linux' in sys.platform:
9 elif 'linux' in sys.platform:
10 matplotlib.use("TkAgg")
10 matplotlib.use("TkAgg")
11 elif 'darwin' in sys.platform:
11 elif 'darwin' in sys.platform:
12 matplotlib.use('TkAgg')
12 matplotlib.use('TkAgg')
13 else:
13 else:
14 from schainpy.utils import log
14 from schainpy.utils import log
15 log.warning('Using default Backend="Agg"', 'INFO')
15 log.warning('Using default Backend="Agg"', 'INFO')
16 matplotlib.use('Agg')
16 matplotlib.use('Agg')
17 # Qt4Agg', 'GTK', 'GTKAgg', 'ps', 'agg', 'cairo', 'MacOSX', 'GTKCairo', 'WXAgg', 'template', 'TkAgg', 'GTK3Cairo', 'GTK3Agg', 'svg', 'WebAgg', 'CocoaAgg', 'emf', 'gdk', 'WX'
17 # Qt4Agg', 'GTK', 'GTKAgg', 'ps', 'agg', 'cairo', 'MacOSX', 'GTKCairo', 'WXAgg', 'template', 'TkAgg', 'GTK3Cairo', 'GTK3Agg', 'svg', 'WebAgg', 'CocoaAgg', 'emf', 'gdk', 'WX'
18 import matplotlib.pyplot
18 import matplotlib.pyplot
19
19
20 from mpl_toolkits.axes_grid1 import make_axes_locatable
20 from mpl_toolkits.axes_grid1 import make_axes_locatable
21 from matplotlib.ticker import FuncFormatter, LinearLocator
21 from matplotlib.ticker import FuncFormatter, LinearLocator
22
22
23 ###########################################
23 ###########################################
24 # Actualizacion de las funciones del driver
24 # Actualizacion de las funciones del driver
25 ###########################################
25 ###########################################
26
26
27 # create jro colormap
27 # create jro colormap
28
28
29 jet_values = matplotlib.pyplot.get_cmap("jet", 100)(numpy.arange(100))[10:90]
29 jet_values = matplotlib.pyplot.get_cmap("jet", 100)(numpy.arange(100))[10:90]
30 blu_values = matplotlib.pyplot.get_cmap(
30 blu_values = matplotlib.pyplot.get_cmap(
31 "seismic_r", 20)(numpy.arange(20))[10:15]
31 "seismic_r", 20)(numpy.arange(20))[10:15]
32 ncmap = matplotlib.colors.LinearSegmentedColormap.from_list(
32 ncmap = matplotlib.colors.LinearSegmentedColormap.from_list(
33 "jro", numpy.vstack((blu_values, jet_values)))
33 "jro", numpy.vstack((blu_values, jet_values)))
34 matplotlib.pyplot.register_cmap(cmap=ncmap)
34 matplotlib.pyplot.register_cmap(cmap=ncmap)
35
35
36
36
37 def createFigure(id, wintitle, width, height, facecolor="w", show=True, dpi=80):
37 def createFigure(id, wintitle, width, height, facecolor="w", show=True, dpi=80):
38
38
39 matplotlib.pyplot.ioff()
39 matplotlib.pyplot.ioff()
40
40
41 fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor, figsize=(
41 fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor, figsize=(
42 1.0 * width / dpi, 1.0 * height / dpi))
42 1.0 * width / dpi, 1.0 * height / dpi))
43 fig.canvas.manager.set_window_title(wintitle)
43 fig.canvas.manager.set_window_title(wintitle)
44 # fig.canvas.manager.resize(width, height)
44 # fig.canvas.manager.resize(width, height)
45 matplotlib.pyplot.ion()
45 matplotlib.pyplot.ion()
46
46
47 if show:
47 if show:
48 matplotlib.pyplot.show()
48 matplotlib.pyplot.show()
49
49
50 return fig
50 return fig
51
51
52
52
53 def closeFigure(show=False, fig=None):
53 def closeFigure(show=False, fig=None):
54
54
55 # matplotlib.pyplot.ioff()
55 # matplotlib.pyplot.ioff()
56 # matplotlib.pyplot.pause(0)
56 # matplotlib.pyplot.pause(0)
57
57
58 if show:
58 if show:
59 matplotlib.pyplot.show()
59 matplotlib.pyplot.show()
60
60
61 if fig != None:
61 if fig != None:
62 matplotlib.pyplot.close(fig)
62 matplotlib.pyplot.close(fig)
63 # matplotlib.pyplot.pause(0)
63 # matplotlib.pyplot.pause(0)
64 # matplotlib.pyplot.ion()
64 # matplotlib.pyplot.ion()
65
65
66 return
66 return
67
67
68 matplotlib.pyplot.close("all")
68 matplotlib.pyplot.close("all")
69 # matplotlib.pyplot.pause(0)
69 # matplotlib.pyplot.pause(0)
70 # matplotlib.pyplot.ion()
70 # matplotlib.pyplot.ion()
71
71
72 return
72 return
73
73
74
74
75 def saveFigure(fig, filename):
75 def saveFigure(fig, filename):
76
76
77 # matplotlib.pyplot.ioff()
77 # matplotlib.pyplot.ioff()
78 fig.savefig(filename, dpi=matplotlib.pyplot.gcf().dpi)
78 fig.savefig(filename, dpi=matplotlib.pyplot.gcf().dpi)
79 # matplotlib.pyplot.ion()
79 # matplotlib.pyplot.ion()
80
80
81
81
82 def clearFigure(fig):
82 def clearFigure(fig):
83
83
84 fig.clf()
84 fig.clf()
85
85
86
86
87 def setWinTitle(fig, title):
87 def setWinTitle(fig, title):
88
88
89 fig.canvas.manager.set_window_title(title)
89 fig.canvas.manager.set_window_title(title)
90
90
91
91
92 def setTitle(fig, title):
92 def setTitle(fig, title):
93
93
94 fig.suptitle(title)
94 fig.suptitle(title)
95
95
96
96
97 def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan, polar=False):
97 def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan, polar=False):
98
98
99 matplotlib.pyplot.ioff()
99 matplotlib.pyplot.ioff()
100 matplotlib.pyplot.figure(fig.number)
100 matplotlib.pyplot.figure(fig.number)
101 axes = matplotlib.pyplot.subplot2grid((nrow, ncol),
101 axes = matplotlib.pyplot.subplot2grid((nrow, ncol),
102 (xpos, ypos),
102 (xpos, ypos),
103 colspan=colspan,
103 colspan=colspan,
104 rowspan=rowspan,
104 rowspan=rowspan,
105 polar=polar)
105 polar=polar)
106
106
107 matplotlib.pyplot.ion()
107 matplotlib.pyplot.ion()
108 return axes
108 return axes
109
109
110
110
111 def setAxesText(ax, text):
111 def setAxesText(ax, text):
112
112
113 ax.annotate(text,
113 ax.annotate(text,
114 xy=(.1, .99),
114 xy=(.1, .99),
115 xycoords='figure fraction',
115 xycoords='figure fraction',
116 horizontalalignment='left',
116 horizontalalignment='left',
117 verticalalignment='top',
117 verticalalignment='top',
118 fontsize=10)
118 fontsize=10)
119
119
120
120
121 def printLabels(ax, xlabel, ylabel, title):
121 def printLabels(ax, xlabel, ylabel, title):
122
122
123 ax.set_xlabel(xlabel, size=11)
123 ax.set_xlabel(xlabel, size=11)
124 ax.set_ylabel(ylabel, size=11)
124 ax.set_ylabel(ylabel, size=11)
125 ax.set_title(title, size=8)
125 ax.set_title(title, size=8)
126
126
127
127
128 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='',
128 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='',
129 ticksize=9, xtick_visible=True, ytick_visible=True,
129 ticksize=9, xtick_visible=True, ytick_visible=True,
130 nxticks=4, nyticks=10,
130 nxticks=4, nyticks=10,
131 grid=None, color='blue'):
131 grid=None, color='blue'):
132 """
132 """
133
133
134 Input:
134 Input:
135 grid : None, 'both', 'x', 'y'
135 grid : None, 'both', 'x', 'y'
136 """
136 """
137
137
138 matplotlib.pyplot.ioff()
138 matplotlib.pyplot.ioff()
139
139
140 ax.set_xlim([xmin, xmax])
140 ax.set_xlim([xmin, xmax])
141 ax.set_ylim([ymin, ymax])
141 ax.set_ylim([ymin, ymax])
142
142
143 printLabels(ax, xlabel, ylabel, title)
143 printLabels(ax, xlabel, ylabel, title)
144
144
145 ######################################################
145 ######################################################
146 if (xmax - xmin) <= 1:
146 if (xmax - xmin) <= 1:
147 xtickspos = numpy.linspace(xmin, xmax, nxticks)
147 xtickspos = numpy.linspace(xmin, xmax, nxticks)
148 xtickspos = numpy.array([float("%.1f" % i) for i in xtickspos])
148 xtickspos = numpy.array([float("%.1f" % i) for i in xtickspos])
149 ax.set_xticks(xtickspos)
149 ax.set_xticks(xtickspos)
150 else:
150 else:
151 xtickspos = numpy.arange(nxticks) * \
151 xtickspos = numpy.arange(nxticks) * \
152 int((xmax - xmin) / (nxticks)) + int(xmin)
152 int((xmax - xmin) / (nxticks)) + int(xmin)
153 # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin)
153 # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin)
154 ax.set_xticks(xtickspos)
154 ax.set_xticks(xtickspos)
155
155
156 for tick in ax.get_xticklabels():
156 for tick in ax.get_xticklabels():
157 tick.set_visible(xtick_visible)
157 tick.set_visible(xtick_visible)
158
158
159 for tick in ax.xaxis.get_major_ticks():
159 for tick in ax.xaxis.get_major_ticks():
160 tick.label.set_fontsize(ticksize)
160 tick.label.set_fontsize(ticksize)
161
161
162 ######################################################
162 ######################################################
163 for tick in ax.get_yticklabels():
163 for tick in ax.get_yticklabels():
164 tick.set_visible(ytick_visible)
164 tick.set_visible(ytick_visible)
165
165
166 for tick in ax.yaxis.get_major_ticks():
166 for tick in ax.yaxis.get_major_ticks():
167 tick.label.set_fontsize(ticksize)
167 tick.label.set_fontsize(ticksize)
168
168
169 ax.plot(x, y, color=color)
169 ax.plot(x, y, color=color)
170 iplot = ax.lines[-1]
170 iplot = ax.lines[-1]
171
171
172 ######################################################
172 ######################################################
173 if '0.' in matplotlib.__version__[0:2]:
173 if '0.' in matplotlib.__version__[0:2]:
174 print "The matplotlib version has to be updated to 1.1 or newer"
174 print("The matplotlib version has to be updated to 1.1 or newer")
175 return iplot
175 return iplot
176
176
177 if '1.0.' in matplotlib.__version__[0:4]:
177 if '1.0.' in matplotlib.__version__[0:4]:
178 print "The matplotlib version has to be updated to 1.1 or newer"
178 print("The matplotlib version has to be updated to 1.1 or newer")
179 return iplot
179 return iplot
180
180
181 if grid != None:
181 if grid != None:
182 ax.grid(b=True, which='major', axis=grid)
182 ax.grid(b=True, which='major', axis=grid)
183
183
184 matplotlib.pyplot.tight_layout()
184 matplotlib.pyplot.tight_layout()
185
185
186 matplotlib.pyplot.ion()
186 matplotlib.pyplot.ion()
187
187
188 return iplot
188 return iplot
189
189
190
190
191 def set_linedata(ax, x, y, idline):
191 def set_linedata(ax, x, y, idline):
192
192
193 ax.lines[idline].set_data(x, y)
193 ax.lines[idline].set_data(x, y)
194
194
195
195
196 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
196 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
197
197
198 ax = iplot.axes
198 ax = iplot.axes
199
199
200 printLabels(ax, xlabel, ylabel, title)
200 printLabels(ax, xlabel, ylabel, title)
201
201
202 set_linedata(ax, x, y, idline=0)
202 set_linedata(ax, x, y, idline=0)
203
203
204
204
205 def addpline(ax, x, y, color, linestyle, lw):
205 def addpline(ax, x, y, color, linestyle, lw):
206
206
207 ax.plot(x, y, color=color, linestyle=linestyle, lw=lw)
207 ax.plot(x, y, color=color, linestyle=linestyle, lw=lw)
208
208
209
209
210 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
210 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
211 xlabel='', ylabel='', title='', ticksize=9,
211 xlabel='', ylabel='', title='', ticksize=9,
212 colormap='jet', cblabel='', cbsize="5%",
212 colormap='jet', cblabel='', cbsize="5%",
213 XAxisAsTime=False):
213 XAxisAsTime=False):
214
214
215 matplotlib.pyplot.ioff()
215 matplotlib.pyplot.ioff()
216
216
217 divider = make_axes_locatable(ax)
217 divider = make_axes_locatable(ax)
218 ax_cb = divider.new_horizontal(size=cbsize, pad=0.05)
218 ax_cb = divider.new_horizontal(size=cbsize, pad=0.05)
219 fig = ax.get_figure()
219 fig = ax.get_figure()
220 fig.add_axes(ax_cb)
220 fig.add_axes(ax_cb)
221
221
222 ax.set_xlim([xmin, xmax])
222 ax.set_xlim([xmin, xmax])
223 ax.set_ylim([ymin, ymax])
223 ax.set_ylim([ymin, ymax])
224
224
225 printLabels(ax, xlabel, ylabel, title)
225 printLabels(ax, xlabel, ylabel, title)
226
226
227 z = numpy.ma.masked_invalid(z)
227 z = numpy.ma.masked_invalid(z)
228 cmap = matplotlib.pyplot.get_cmap(colormap)
228 cmap = matplotlib.pyplot.get_cmap(colormap)
229 cmap.set_bad('black', 1.)
229 cmap.set_bad('black', 1.)
230 imesh = ax.pcolormesh(x, y, z.T, vmin=zmin, vmax=zmax, cmap=cmap)
230 imesh = ax.pcolormesh(x, y, z.T, vmin=zmin, vmax=zmax, cmap=cmap)
231 cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
231 cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
232 cb.set_label(cblabel)
232 cb.set_label(cblabel)
233
233
234 # for tl in ax_cb.get_yticklabels():
234 # for tl in ax_cb.get_yticklabels():
235 # tl.set_visible(True)
235 # tl.set_visible(True)
236
236
237 for tick in ax.yaxis.get_major_ticks():
237 for tick in ax.yaxis.get_major_ticks():
238 tick.label.set_fontsize(ticksize)
238 tick.label.set_fontsize(ticksize)
239
239
240 for tick in ax.xaxis.get_major_ticks():
240 for tick in ax.xaxis.get_major_ticks():
241 tick.label.set_fontsize(ticksize)
241 tick.label.set_fontsize(ticksize)
242
242
243 for tick in cb.ax.get_yticklabels():
243 for tick in cb.ax.get_yticklabels():
244 tick.set_fontsize(ticksize)
244 tick.set_fontsize(ticksize)
245
245
246 ax_cb.yaxis.tick_right()
246 ax_cb.yaxis.tick_right()
247
247
248 if '0.' in matplotlib.__version__[0:2]:
248 if '0.' in matplotlib.__version__[0:2]:
249 print "The matplotlib version has to be updated to 1.1 or newer"
249 print("The matplotlib version has to be updated to 1.1 or newer")
250 return imesh
250 return imesh
251
251
252 if '1.0.' in matplotlib.__version__[0:4]:
252 if '1.0.' in matplotlib.__version__[0:4]:
253 print "The matplotlib version has to be updated to 1.1 or newer"
253 print("The matplotlib version has to be updated to 1.1 or newer")
254 return imesh
254 return imesh
255
255
256 matplotlib.pyplot.tight_layout()
256 matplotlib.pyplot.tight_layout()
257
257
258 if XAxisAsTime:
258 if XAxisAsTime:
259
259
260 def func(x, pos): return ('%s') % (
260 def func(x, pos): return ('%s') % (
261 datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
261 datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
262 ax.xaxis.set_major_formatter(FuncFormatter(func))
262 ax.xaxis.set_major_formatter(FuncFormatter(func))
263 ax.xaxis.set_major_locator(LinearLocator(7))
263 ax.xaxis.set_major_locator(LinearLocator(7))
264
264
265 matplotlib.pyplot.ion()
265 matplotlib.pyplot.ion()
266 return imesh
266 return imesh
267
267
268
268
269 def pcolor(imesh, z, xlabel='', ylabel='', title=''):
269 def pcolor(imesh, z, xlabel='', ylabel='', title=''):
270
270
271 z = z.T
271 z = z.T
272 ax = imesh.axes
272 ax = imesh.axes
273 printLabels(ax, xlabel, ylabel, title)
273 printLabels(ax, xlabel, ylabel, title)
274 imesh.set_array(z.ravel())
274 imesh.set_array(z.ravel())
275
275
276
276
277 def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
277 def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
278
278
279 printLabels(ax, xlabel, ylabel, title)
279 printLabels(ax, xlabel, ylabel, title)
280
280
281 ax.pcolormesh(x, y, z.T, vmin=zmin, vmax=zmax,
281 ax.pcolormesh(x, y, z.T, vmin=zmin, vmax=zmax,
282 cmap=matplotlib.pyplot.get_cmap(colormap))
282 cmap=matplotlib.pyplot.get_cmap(colormap))
283
283
284
284
285 def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
285 def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
286
286
287 printLabels(ax, xlabel, ylabel, title)
287 printLabels(ax, xlabel, ylabel, title)
288
288
289 ax.collections.remove(ax.collections[0])
289 ax.collections.remove(ax.collections[0])
290
290
291 z = numpy.ma.masked_invalid(z)
291 z = numpy.ma.masked_invalid(z)
292
292
293 cmap = matplotlib.pyplot.get_cmap(colormap)
293 cmap = matplotlib.pyplot.get_cmap(colormap)
294 cmap.set_bad('black', 1.)
294 cmap.set_bad('black', 1.)
295
295
296 ax.pcolormesh(x, y, z.T, vmin=zmin, vmax=zmax, cmap=cmap)
296 ax.pcolormesh(x, y, z.T, vmin=zmin, vmax=zmax, cmap=cmap)
297
297
298
298
299 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
299 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
300 ticksize=9, xtick_visible=True, ytick_visible=True,
300 ticksize=9, xtick_visible=True, ytick_visible=True,
301 nxticks=4, nyticks=10,
301 nxticks=4, nyticks=10,
302 grid=None):
302 grid=None):
303 """
303 """
304
304
305 Input:
305 Input:
306 grid : None, 'both', 'x', 'y'
306 grid : None, 'both', 'x', 'y'
307 """
307 """
308
308
309 matplotlib.pyplot.ioff()
309 matplotlib.pyplot.ioff()
310
310
311 lines = ax.plot(x.T, y)
311 lines = ax.plot(x.T, y)
312 leg = ax.legend(lines, legendlabels, loc='upper right')
312 leg = ax.legend(lines, legendlabels, loc='upper right')
313 leg.get_frame().set_alpha(0.5)
313 leg.get_frame().set_alpha(0.5)
314 ax.set_xlim([xmin, xmax])
314 ax.set_xlim([xmin, xmax])
315 ax.set_ylim([ymin, ymax])
315 ax.set_ylim([ymin, ymax])
316 printLabels(ax, xlabel, ylabel, title)
316 printLabels(ax, xlabel, ylabel, title)
317
317
318 xtickspos = numpy.arange(nxticks) * \
318 xtickspos = numpy.arange(nxticks) * \
319 int((xmax - xmin) / (nxticks)) + int(xmin)
319 int((xmax - xmin) / (nxticks)) + int(xmin)
320 ax.set_xticks(xtickspos)
320 ax.set_xticks(xtickspos)
321
321
322 for tick in ax.get_xticklabels():
322 for tick in ax.get_xticklabels():
323 tick.set_visible(xtick_visible)
323 tick.set_visible(xtick_visible)
324
324
325 for tick in ax.xaxis.get_major_ticks():
325 for tick in ax.xaxis.get_major_ticks():
326 tick.label.set_fontsize(ticksize)
326 tick.label.set_fontsize(ticksize)
327
327
328 for tick in ax.get_yticklabels():
328 for tick in ax.get_yticklabels():
329 tick.set_visible(ytick_visible)
329 tick.set_visible(ytick_visible)
330
330
331 for tick in ax.yaxis.get_major_ticks():
331 for tick in ax.yaxis.get_major_ticks():
332 tick.label.set_fontsize(ticksize)
332 tick.label.set_fontsize(ticksize)
333
333
334 iplot = ax.lines[-1]
334 iplot = ax.lines[-1]
335
335
336 if '0.' in matplotlib.__version__[0:2]:
336 if '0.' in matplotlib.__version__[0:2]:
337 print "The matplotlib version has to be updated to 1.1 or newer"
337 print("The matplotlib version has to be updated to 1.1 or newer")
338 return iplot
338 return iplot
339
339
340 if '1.0.' in matplotlib.__version__[0:4]:
340 if '1.0.' in matplotlib.__version__[0:4]:
341 print "The matplotlib version has to be updated to 1.1 or newer"
341 print("The matplotlib version has to be updated to 1.1 or newer")
342 return iplot
342 return iplot
343
343
344 if grid != None:
344 if grid != None:
345 ax.grid(b=True, which='major', axis=grid)
345 ax.grid(b=True, which='major', axis=grid)
346
346
347 matplotlib.pyplot.tight_layout()
347 matplotlib.pyplot.tight_layout()
348
348
349 matplotlib.pyplot.ion()
349 matplotlib.pyplot.ion()
350
350
351 return iplot
351 return iplot
352
352
353
353
354 def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''):
354 def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''):
355
355
356 ax = iplot.axes
356 ax = iplot.axes
357
357
358 printLabels(ax, xlabel, ylabel, title)
358 printLabels(ax, xlabel, ylabel, title)
359
359
360 for i in range(len(ax.lines)):
360 for i in range(len(ax.lines)):
361 line = ax.lines[i]
361 line = ax.lines[i]
362 line.set_data(x[i, :], y)
362 line.set_data(x[i, :], y)
363
363
364
364
365 def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
365 def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
366 ticksize=9, xtick_visible=True, ytick_visible=True,
366 ticksize=9, xtick_visible=True, ytick_visible=True,
367 nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None",
367 nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None",
368 grid=None, XAxisAsTime=False):
368 grid=None, XAxisAsTime=False):
369 """
369 """
370
370
371 Input:
371 Input:
372 grid : None, 'both', 'x', 'y'
372 grid : None, 'both', 'x', 'y'
373 """
373 """
374
374
375 matplotlib.pyplot.ioff()
375 matplotlib.pyplot.ioff()
376
376
377 # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle)
377 # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle)
378 lines = ax.plot(x, y.T)
378 lines = ax.plot(x, y.T)
379 # leg = ax.legend(lines, legendlabels, loc=2, bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \
379 # leg = ax.legend(lines, legendlabels, loc=2, bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \
380 # handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.)
380 # handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.)
381
381
382 leg = ax.legend(lines, legendlabels,
382 leg = ax.legend(lines, legendlabels,
383 loc='upper right', bbox_to_anchor=(1.16, 1), borderaxespad=0)
383 loc='upper right', bbox_to_anchor=(1.16, 1), borderaxespad=0)
384
384
385 for label in leg.get_texts():
385 for label in leg.get_texts():
386 label.set_fontsize(9)
386 label.set_fontsize(9)
387
387
388 ax.set_xlim([xmin, xmax])
388 ax.set_xlim([xmin, xmax])
389 ax.set_ylim([ymin, ymax])
389 ax.set_ylim([ymin, ymax])
390 printLabels(ax, xlabel, ylabel, title)
390 printLabels(ax, xlabel, ylabel, title)
391
391
392 # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
392 # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
393 # ax.set_xticks(xtickspos)
393 # ax.set_xticks(xtickspos)
394
394
395 for tick in ax.get_xticklabels():
395 for tick in ax.get_xticklabels():
396 tick.set_visible(xtick_visible)
396 tick.set_visible(xtick_visible)
397
397
398 for tick in ax.xaxis.get_major_ticks():
398 for tick in ax.xaxis.get_major_ticks():
399 tick.label.set_fontsize(ticksize)
399 tick.label.set_fontsize(ticksize)
400
400
401 for tick in ax.get_yticklabels():
401 for tick in ax.get_yticklabels():
402 tick.set_visible(ytick_visible)
402 tick.set_visible(ytick_visible)
403
403
404 for tick in ax.yaxis.get_major_ticks():
404 for tick in ax.yaxis.get_major_ticks():
405 tick.label.set_fontsize(ticksize)
405 tick.label.set_fontsize(ticksize)
406
406
407 iplot = ax.lines[-1]
407 iplot = ax.lines[-1]
408
408
409 if '0.' in matplotlib.__version__[0:2]:
409 if '0.' in matplotlib.__version__[0:2]:
410 print "The matplotlib version has to be updated to 1.1 or newer"
410 print("The matplotlib version has to be updated to 1.1 or newer")
411 return iplot
411 return iplot
412
412
413 if '1.0.' in matplotlib.__version__[0:4]:
413 if '1.0.' in matplotlib.__version__[0:4]:
414 print "The matplotlib version has to be updated to 1.1 or newer"
414 print("The matplotlib version has to be updated to 1.1 or newer")
415 return iplot
415 return iplot
416
416
417 if grid != None:
417 if grid != None:
418 ax.grid(b=True, which='major', axis=grid)
418 ax.grid(b=True, which='major', axis=grid)
419
419
420 matplotlib.pyplot.tight_layout()
420 matplotlib.pyplot.tight_layout()
421
421
422 if XAxisAsTime:
422 if XAxisAsTime:
423
423
424 def func(x, pos): return ('%s') % (
424 def func(x, pos): return ('%s') % (
425 datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
425 datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
426 ax.xaxis.set_major_formatter(FuncFormatter(func))
426 ax.xaxis.set_major_formatter(FuncFormatter(func))
427 ax.xaxis.set_major_locator(LinearLocator(7))
427 ax.xaxis.set_major_locator(LinearLocator(7))
428
428
429 matplotlib.pyplot.ion()
429 matplotlib.pyplot.ion()
430
430
431 return iplot
431 return iplot
432
432
433
433
434 def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''):
434 def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''):
435
435
436 ax = iplot.axes
436 ax = iplot.axes
437
437
438 printLabels(ax, xlabel, ylabel, title)
438 printLabels(ax, xlabel, ylabel, title)
439
439
440 for i in range(len(ax.lines)):
440 for i in range(len(ax.lines)):
441 line = ax.lines[i]
441 line = ax.lines[i]
442 line.set_data(x, y[i, :])
442 line.set_data(x, y[i, :])
443
443
444
444
445 def createPolar(ax, x, y,
445 def createPolar(ax, x, y,
446 xlabel='', ylabel='', title='', ticksize=9,
446 xlabel='', ylabel='', title='', ticksize=9,
447 colormap='jet', cblabel='', cbsize="5%",
447 colormap='jet', cblabel='', cbsize="5%",
448 XAxisAsTime=False):
448 XAxisAsTime=False):
449
449
450 matplotlib.pyplot.ioff()
450 matplotlib.pyplot.ioff()
451
451
452 ax.plot(x, y, 'bo', markersize=5)
452 ax.plot(x, y, 'bo', markersize=5)
453 # ax.set_rmax(90)
453 # ax.set_rmax(90)
454 ax.set_ylim(0, 90)
454 ax.set_ylim(0, 90)
455 ax.set_yticks(numpy.arange(0, 90, 20))
455 ax.set_yticks(numpy.arange(0, 90, 20))
456 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center' ,size='11')
456 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center' ,size='11')
457 # ax.text(0, 50, ylabel, rotation='vertical', va ='center', ha = 'left' ,size='11')
457 # ax.text(0, 50, ylabel, rotation='vertical', va ='center', ha = 'left' ,size='11')
458 # ax.text(100, 100, 'example', ha='left', va='center', rotation='vertical')
458 # ax.text(100, 100, 'example', ha='left', va='center', rotation='vertical')
459 ax.yaxis.labelpad = 40
459 ax.yaxis.labelpad = 40
460 printLabels(ax, xlabel, ylabel, title)
460 printLabels(ax, xlabel, ylabel, title)
461 iplot = ax.lines[-1]
461 iplot = ax.lines[-1]
462
462
463 if '0.' in matplotlib.__version__[0:2]:
463 if '0.' in matplotlib.__version__[0:2]:
464 print "The matplotlib version has to be updated to 1.1 or newer"
464 print("The matplotlib version has to be updated to 1.1 or newer")
465 return iplot
465 return iplot
466
466
467 if '1.0.' in matplotlib.__version__[0:4]:
467 if '1.0.' in matplotlib.__version__[0:4]:
468 print "The matplotlib version has to be updated to 1.1 or newer"
468 print("The matplotlib version has to be updated to 1.1 or newer")
469 return iplot
469 return iplot
470
470
471 # if grid != None:
471 # if grid != None:
472 # ax.grid(b=True, which='major', axis=grid)
472 # ax.grid(b=True, which='major', axis=grid)
473
473
474 matplotlib.pyplot.tight_layout()
474 matplotlib.pyplot.tight_layout()
475
475
476 matplotlib.pyplot.ion()
476 matplotlib.pyplot.ion()
477
477
478 return iplot
478 return iplot
479
479
480
480
481 def polar(iplot, x, y, xlabel='', ylabel='', title=''):
481 def polar(iplot, x, y, xlabel='', ylabel='', title=''):
482
482
483 ax = iplot.axes
483 ax = iplot.axes
484
484
485 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11')
485 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11')
486 printLabels(ax, xlabel, ylabel, title)
486 printLabels(ax, xlabel, ylabel, title)
487
487
488 set_linedata(ax, x, y, idline=0)
488 set_linedata(ax, x, y, idline=0)
489
489
490
490
491 def draw(fig):
491 def draw(fig):
492
492
493 if type(fig) == 'int':
493 if type(fig) == 'int':
494 raise ValueError, "Error drawing: Fig parameter should be a matplotlib figure object figure"
494 raise ValueError("Error drawing: Fig parameter should be a matplotlib figure object figure")
495
495
496 fig.canvas.draw()
496 fig.canvas.draw()
497
497
498
498
499 def pause(interval=0.000001):
499 def pause(interval=0.000001):
500
500
501 matplotlib.pyplot.pause(interval)
501 matplotlib.pyplot.pause(interval) No newline at end of file
@@ -1,331 +1,331
1 import os
1 import os
2 import sys
2 import sys
3 import glob
3 import glob
4 import fnmatch
4 import fnmatch
5 import datetime
5 import datetime
6 import time
6 import time
7 import re
7 import re
8 import h5py
8 import h5py
9 import numpy
9 import numpy
10
10
11 from scipy.optimize import curve_fit
11 from scipy.optimize import curve_fit
12 from scipy import asarray as ar, exp
12 from scipy import asarray as ar, exp
13 from scipy import stats
13 from scipy import stats
14
14
15 from duplicity.path import Path
15 from duplicity.path import Path
16 from numpy.ma.core import getdata
16 from numpy.ma.core import getdata
17
17
18 SPEED_OF_LIGHT = 299792458
18 SPEED_OF_LIGHT = 299792458
19 SPEED_OF_LIGHT = 3e8
19 SPEED_OF_LIGHT = 3e8
20
20
21 try:
21 try:
22 from gevent import sleep
22 from gevent import sleep
23 except:
23 except:
24 from time import sleep
24 from time import sleep
25
25
26 from schainpy.model.data.jrodata import Spectra
26 from schainpy.model.data.jrodata import Spectra
27 #from schainpy.model.data.BLTRheaderIO import FileHeader, RecordHeader
27 #from schainpy.model.data.BLTRheaderIO import FileHeader, RecordHeader
28 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
28 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
29 #from schainpy.model.io.jroIO_bltr import BLTRReader
29 #from schainpy.model.io.jroIO_bltr import BLTRReader
30 from numpy import imag, shape, NaN
30 from numpy import imag, shape, NaN
31
31
32
32
33 startFp = open(
33 startFp = open(
34 '/home/erick/Documents/MIRA35C/20160117/20160117_0000.zspc', "rb")
34 '/home/erick/Documents/MIRA35C/20160117/20160117_0000.zspc', "rb")
35
35
36
36
37 FILE_HEADER = numpy.dtype([ # HEADER 1024bytes
37 FILE_HEADER = numpy.dtype([ # HEADER 1024bytes
38 ('Hname', numpy.str_, 32), # Original file name
38 ('Hname', numpy.str_, 32), # Original file name
39 # Date and time when the file was created
39 # Date and time when the file was created
40 ('Htime', numpy.str_, 32),
40 ('Htime', numpy.str_, 32),
41 # Name of operator who created the file
41 # Name of operator who created the file
42 ('Hoper', numpy.str_, 64),
42 ('Hoper', numpy.str_, 64),
43 # Place where the measurements was carried out
43 # Place where the measurements was carried out
44 ('Hplace', numpy.str_, 128),
44 ('Hplace', numpy.str_, 128),
45 # Description of measurements
45 # Description of measurements
46 ('Hdescr', numpy.str_, 256),
46 ('Hdescr', numpy.str_, 256),
47 ('Hdummy', numpy.str_, 512), # Reserved space
47 ('Hdummy', numpy.str_, 512), # Reserved space
48 # Main chunk
48 # Main chunk
49 ('Msign', '<i4'), # Main chunk signature FZKF or NUIG
49 ('Msign', '<i4'), # Main chunk signature FZKF or NUIG
50 ('MsizeData', '<i4'), # Size of data block main chunk
50 ('MsizeData', '<i4'), # Size of data block main chunk
51 # Processing DSP parameters
51 # Processing DSP parameters
52 ('PPARsign', '<i4'), # PPAR signature
52 ('PPARsign', '<i4'), # PPAR signature
53 ('PPARsize', '<i4'), # PPAR size of block
53 ('PPARsize', '<i4'), # PPAR size of block
54 ('PPARprf', '<i4'), # Pulse repetition frequency
54 ('PPARprf', '<i4'), # Pulse repetition frequency
55 ('PPARpdr', '<i4'), # Pulse duration
55 ('PPARpdr', '<i4'), # Pulse duration
56 ('PPARsft', '<i4'), # FFT length
56 ('PPARsft', '<i4'), # FFT length
57 # Number of spectral (in-coherent) averages
57 # Number of spectral (in-coherent) averages
58 ('PPARavc', '<i4'),
58 ('PPARavc', '<i4'),
59 # Number of lowest range gate for moment estimation
59 # Number of lowest range gate for moment estimation
60 ('PPARihp', '<i4'),
60 ('PPARihp', '<i4'),
61 # Count for gates for moment estimation
61 # Count for gates for moment estimation
62 ('PPARchg', '<i4'),
62 ('PPARchg', '<i4'),
63 # switch on/off polarimetric measurements. Should be 1.
63 # switch on/off polarimetric measurements. Should be 1.
64 ('PPARpol', '<i4'),
64 ('PPARpol', '<i4'),
65 # Service DSP parameters
65 # Service DSP parameters
66 # STC attenuation on the lowest ranges on/off
66 # STC attenuation on the lowest ranges on/off
67 ('SPARatt', '<i4'),
67 ('SPARatt', '<i4'),
68 ('SPARtx', '<i4'), # OBSOLETE
68 ('SPARtx', '<i4'), # OBSOLETE
69 ('SPARaddGain0', '<f4'), # OBSOLETE
69 ('SPARaddGain0', '<f4'), # OBSOLETE
70 ('SPARaddGain1', '<f4'), # OBSOLETE
70 ('SPARaddGain1', '<f4'), # OBSOLETE
71 # Debug only. It normal mode it is 0.
71 # Debug only. It normal mode it is 0.
72 ('SPARwnd', '<i4'),
72 ('SPARwnd', '<i4'),
73 # Delay between sync pulse and tx pulse for phase corr, ns
73 # Delay between sync pulse and tx pulse for phase corr, ns
74 ('SPARpos', '<i4'),
74 ('SPARpos', '<i4'),
75 # "add to pulse" to compensate for delay between the leading edge of driver pulse and envelope of the RF signal.
75 # "add to pulse" to compensate for delay between the leading edge of driver pulse and envelope of the RF signal.
76 ('SPARadd', '<i4'),
76 ('SPARadd', '<i4'),
77 # Time for measuring txn pulse phase. OBSOLETE
77 # Time for measuring txn pulse phase. OBSOLETE
78 ('SPARlen', '<i4'),
78 ('SPARlen', '<i4'),
79 ('SPARcal', '<i4'), # OBSOLETE
79 ('SPARcal', '<i4'), # OBSOLETE
80 ('SPARnos', '<i4'), # OBSOLETE
80 ('SPARnos', '<i4'), # OBSOLETE
81 ('SPARof0', '<i4'), # detection threshold
81 ('SPARof0', '<i4'), # detection threshold
82 ('SPARof1', '<i4'), # OBSOLETE
82 ('SPARof1', '<i4'), # OBSOLETE
83 ('SPARswt', '<i4'), # 2nd moment estimation threshold
83 ('SPARswt', '<i4'), # 2nd moment estimation threshold
84 ('SPARsum', '<i4'), # OBSOLETE
84 ('SPARsum', '<i4'), # OBSOLETE
85 ('SPARosc', '<i4'), # flag Oscillosgram mode
85 ('SPARosc', '<i4'), # flag Oscillosgram mode
86 ('SPARtst', '<i4'), # OBSOLETE
86 ('SPARtst', '<i4'), # OBSOLETE
87 ('SPARcor', '<i4'), # OBSOLETE
87 ('SPARcor', '<i4'), # OBSOLETE
88 ('SPARofs', '<i4'), # OBSOLETE
88 ('SPARofs', '<i4'), # OBSOLETE
89 # Hildebrand div noise detection on noise gate
89 # Hildebrand div noise detection on noise gate
90 ('SPARhsn', '<i4'),
90 ('SPARhsn', '<i4'),
91 # Hildebrand div noise detection on all gates
91 # Hildebrand div noise detection on all gates
92 ('SPARhsa', '<f4'),
92 ('SPARhsa', '<f4'),
93 ('SPARcalibPow_M', '<f4'), # OBSOLETE
93 ('SPARcalibPow_M', '<f4'), # OBSOLETE
94 ('SPARcalibSNR_M', '<f4'), # OBSOLETE
94 ('SPARcalibSNR_M', '<f4'), # OBSOLETE
95 ('SPARcalibPow_S', '<f4'), # OBSOLETE
95 ('SPARcalibPow_S', '<f4'), # OBSOLETE
96 ('SPARcalibSNR_S', '<f4'), # OBSOLETE
96 ('SPARcalibSNR_S', '<f4'), # OBSOLETE
97 # Lowest range gate for spectra saving Raw_Gate1 >=5
97 # Lowest range gate for spectra saving Raw_Gate1 >=5
98 ('SPARrawGate1', '<i4'),
98 ('SPARrawGate1', '<i4'),
99 # Number of range gates with atmospheric signal
99 # Number of range gates with atmospheric signal
100 ('SPARrawGate2', '<i4'),
100 ('SPARrawGate2', '<i4'),
101 # flag - IQ or spectra saving on/off
101 # flag - IQ or spectra saving on/off
102 ('SPARraw', '<i4'),
102 ('SPARraw', '<i4'),
103 ('SPARprc', '<i4'), ]) # flag - Moment estimation switched on/off
103 ('SPARprc', '<i4'), ]) # flag - Moment estimation switched on/off
104
104
105
105
106 self.Hname = None
106 self.Hname = None
107 self.Htime = None
107 self.Htime = None
108 self.Hoper = None
108 self.Hoper = None
109 self.Hplace = None
109 self.Hplace = None
110 self.Hdescr = None
110 self.Hdescr = None
111 self.Hdummy = None
111 self.Hdummy = None
112
112
113 self.Msign = None
113 self.Msign = None
114 self.MsizeData = None
114 self.MsizeData = None
115
115
116 self.PPARsign = None
116 self.PPARsign = None
117 self.PPARsize = None
117 self.PPARsize = None
118 self.PPARprf = None
118 self.PPARprf = None
119 self.PPARpdr = None
119 self.PPARpdr = None
120 self.PPARsft = None
120 self.PPARsft = None
121 self.PPARavc = None
121 self.PPARavc = None
122 self.PPARihp = None
122 self.PPARihp = None
123 self.PPARchg = None
123 self.PPARchg = None
124 self.PPARpol = None
124 self.PPARpol = None
125 # Service DSP parameters
125 # Service DSP parameters
126 self.SPARatt = None
126 self.SPARatt = None
127 self.SPARtx = None
127 self.SPARtx = None
128 self.SPARaddGain0 = None
128 self.SPARaddGain0 = None
129 self.SPARaddGain1 = None
129 self.SPARaddGain1 = None
130 self.SPARwnd = None
130 self.SPARwnd = None
131 self.SPARpos = None
131 self.SPARpos = None
132 self.SPARadd = None
132 self.SPARadd = None
133 self.SPARlen = None
133 self.SPARlen = None
134 self.SPARcal = None
134 self.SPARcal = None
135 self.SPARnos = None
135 self.SPARnos = None
136 self.SPARof0 = None
136 self.SPARof0 = None
137 self.SPARof1 = None
137 self.SPARof1 = None
138 self.SPARswt = None
138 self.SPARswt = None
139 self.SPARsum = None
139 self.SPARsum = None
140 self.SPARosc = None
140 self.SPARosc = None
141 self.SPARtst = None
141 self.SPARtst = None
142 self.SPARcor = None
142 self.SPARcor = None
143 self.SPARofs = None
143 self.SPARofs = None
144 self.SPARhsn = None
144 self.SPARhsn = None
145 self.SPARhsa = None
145 self.SPARhsa = None
146 self.SPARcalibPow_M = None
146 self.SPARcalibPow_M = None
147 self.SPARcalibSNR_M = None
147 self.SPARcalibSNR_M = None
148 self.SPARcalibPow_S = None
148 self.SPARcalibPow_S = None
149 self.SPARcalibSNR_S = None
149 self.SPARcalibSNR_S = None
150 self.SPARrawGate1 = None
150 self.SPARrawGate1 = None
151 self.SPARrawGate2 = None
151 self.SPARrawGate2 = None
152 self.SPARraw = None
152 self.SPARraw = None
153 self.SPARprc = None
153 self.SPARprc = None
154
154
155
155
156 header = numpy.fromfile(fp, FILE_HEADER, 1)
156 header = numpy.fromfile(fp, FILE_HEADER, 1)
157 ''' numpy.fromfile(file, dtype, count, sep='')
157 ''' numpy.fromfile(file, dtype, count, sep='')
158 file : file or str
158 file : file or str
159 Open file object or filename.
159 Open file object or filename.
160
160
161 dtype : data-type
161 dtype : data-type
162 Data type of the returned array. For binary files, it is used to determine
162 Data type of the returned array. For binary files, it is used to determine
163 the size and byte-order of the items in the file.
163 the size and byte-order of the items in the file.
164
164
165 count : int
165 count : int
166 Number of items to read. -1 means all items (i.e., the complete file).
166 Number of items to read. -1 means all items (i.e., the complete file).
167
167
168 sep : str
168 sep : str
169 Separator between items if file is a text file. Empty ("") separator means
169 Separator between items if file is a text file. Empty ("") separator means
170 the file should be treated as binary. Spaces (" ") in the separator match zero
170 the file should be treated as binary. Spaces (" ") in the separator match zero
171 or more whitespace characters. A separator consisting only of spaces must match
171 or more whitespace characters. A separator consisting only of spaces must match
172 at least one whitespace.
172 at least one whitespace.
173
173
174 '''
174 '''
175
175
176 Hname = str(header['Hname'][0])
176 Hname = str(header['Hname'][0])
177 Htime = str(header['Htime'][0])
177 Htime = str(header['Htime'][0])
178 Hoper = str(header['Hoper'][0])
178 Hoper = str(header['Hoper'][0])
179 Hplace = str(header['Hplace'][0])
179 Hplace = str(header['Hplace'][0])
180 Hdescr = str(header['Hdescr'][0])
180 Hdescr = str(header['Hdescr'][0])
181 Hdummy = str(header['Hdummy'][0])
181 Hdummy = str(header['Hdummy'][0])
182
182
183 Msign = header['Msign'][0]
183 Msign = header['Msign'][0]
184 MsizeData = header['MsizeData'][0]
184 MsizeData = header['MsizeData'][0]
185
185
186 PPARsign = header['PPARsign'][0]
186 PPARsign = header['PPARsign'][0]
187 PPARsize = header['PPARsize'][0]
187 PPARsize = header['PPARsize'][0]
188 PPARprf = header['PPARprf'][0]
188 PPARprf = header['PPARprf'][0]
189 PPARpdr = header['PPARpdr'][0]
189 PPARpdr = header['PPARpdr'][0]
190 PPARsft = header['PPARsft'][0]
190 PPARsft = header['PPARsft'][0]
191 PPARavc = header['PPARavc'][0]
191 PPARavc = header['PPARavc'][0]
192 PPARihp = header['PPARihp'][0]
192 PPARihp = header['PPARihp'][0]
193 PPARchg = header['PPARchg'][0]
193 PPARchg = header['PPARchg'][0]
194 PPARpol = header['PPARpol'][0]
194 PPARpol = header['PPARpol'][0]
195 # Service DSP parameters
195 # Service DSP parameters
196 SPARatt = header['SPARatt'][0]
196 SPARatt = header['SPARatt'][0]
197 SPARtx = header['SPARtx'][0]
197 SPARtx = header['SPARtx'][0]
198 SPARaddGain0 = header['SPARaddGain0'][0]
198 SPARaddGain0 = header['SPARaddGain0'][0]
199 SPARaddGain1 = header['SPARaddGain1'][0]
199 SPARaddGain1 = header['SPARaddGain1'][0]
200 SPARwnd = header['SPARwnd'][0]
200 SPARwnd = header['SPARwnd'][0]
201 SPARpos = header['SPARpos'][0]
201 SPARpos = header['SPARpos'][0]
202 SPARadd = header['SPARadd'][0]
202 SPARadd = header['SPARadd'][0]
203 SPARlen = header['SPARlen'][0]
203 SPARlen = header['SPARlen'][0]
204 SPARcal = header['SPARcal'][0]
204 SPARcal = header['SPARcal'][0]
205 SPARnos = header['SPARnos'][0]
205 SPARnos = header['SPARnos'][0]
206 SPARof0 = header['SPARof0'][0]
206 SPARof0 = header['SPARof0'][0]
207 SPARof1 = header['SPARof1'][0]
207 SPARof1 = header['SPARof1'][0]
208 SPARswt = header['SPARswt'][0]
208 SPARswt = header['SPARswt'][0]
209 SPARsum = header['SPARsum'][0]
209 SPARsum = header['SPARsum'][0]
210 SPARosc = header['SPARosc'][0]
210 SPARosc = header['SPARosc'][0]
211 SPARtst = header['SPARtst'][0]
211 SPARtst = header['SPARtst'][0]
212 SPARcor = header['SPARcor'][0]
212 SPARcor = header['SPARcor'][0]
213 SPARofs = header['SPARofs'][0]
213 SPARofs = header['SPARofs'][0]
214 SPARhsn = header['SPARhsn'][0]
214 SPARhsn = header['SPARhsn'][0]
215 SPARhsa = header['SPARhsa'][0]
215 SPARhsa = header['SPARhsa'][0]
216 SPARcalibPow_M = header['SPARcalibPow_M'][0]
216 SPARcalibPow_M = header['SPARcalibPow_M'][0]
217 SPARcalibSNR_M = header['SPARcalibSNR_M'][0]
217 SPARcalibSNR_M = header['SPARcalibSNR_M'][0]
218 SPARcalibPow_S = header['SPARcalibPow_S'][0]
218 SPARcalibPow_S = header['SPARcalibPow_S'][0]
219 SPARcalibSNR_S = header['SPARcalibSNR_S'][0]
219 SPARcalibSNR_S = header['SPARcalibSNR_S'][0]
220 SPARrawGate1 = header['SPARrawGate1'][0]
220 SPARrawGate1 = header['SPARrawGate1'][0]
221 SPARrawGate2 = header['SPARrawGate2'][0]
221 SPARrawGate2 = header['SPARrawGate2'][0]
222 SPARraw = header['SPARraw'][0]
222 SPARraw = header['SPARraw'][0]
223 SPARprc = header['SPARprc'][0]
223 SPARprc = header['SPARprc'][0]
224
224
225
225
226 SRVI_STRUCTURE = numpy.dtype([
226 SRVI_STRUCTURE = numpy.dtype([
227 ('frame_cnt', '<u4'),
227 ('frame_cnt', '<u4'),
228 ('time_t', '<u4'), #
228 ('time_t', '<u4'), #
229 ('tpow', '<f4'), #
229 ('tpow', '<f4'), #
230 ('npw1', '<f4'), #
230 ('npw1', '<f4'), #
231 ('npw2', '<f4'), #
231 ('npw2', '<f4'), #
232 ('cpw1', '<f4'), #
232 ('cpw1', '<f4'), #
233 ('pcw2', '<f4'), #
233 ('pcw2', '<f4'), #
234 ('ps_err', '<u4'), #
234 ('ps_err', '<u4'), #
235 ('te_err', '<u4'), #
235 ('te_err', '<u4'), #
236 ('rc_err', '<u4'), #
236 ('rc_err', '<u4'), #
237 ('grs1', '<u4'), #
237 ('grs1', '<u4'), #
238 ('grs2', '<u4'), #
238 ('grs2', '<u4'), #
239 ('azipos', '<f4'), #
239 ('azipos', '<f4'), #
240 ('azivel', '<f4'), #
240 ('azivel', '<f4'), #
241 ('elvpos', '<f4'), #
241 ('elvpos', '<f4'), #
242 ('elvvel', '<f4'), #
242 ('elvvel', '<f4'), #
243 ('northAngle', '<f4'),
243 ('northAngle', '<f4'),
244 ('microsec', '<u4'), #
244 ('microsec', '<u4'), #
245 ('azisetvel', '<f4'), #
245 ('azisetvel', '<f4'), #
246 ('elvsetpos', '<f4'), #
246 ('elvsetpos', '<f4'), #
247 ('RadarConst', '<f4'), ]) #
247 ('RadarConst', '<f4'), ]) #
248
248
249 JUMP_STRUCTURE = numpy.dtype([
249 JUMP_STRUCTURE = numpy.dtype([
250 ('jump', '<u140'),
250 ('jump', '<u140'),
251 ('SizeOfDataBlock1', numpy.str_, 32),
251 ('SizeOfDataBlock1', numpy.str_, 32),
252 ('jump', '<i4'),
252 ('jump', '<i4'),
253 ('DataBlockTitleSRVI1', numpy.str_, 32),
253 ('DataBlockTitleSRVI1', numpy.str_, 32),
254 ('SizeOfSRVI1', '<i4'), ])
254 ('SizeOfSRVI1', '<i4'), ])
255
255
256
256
257 # frame_cnt=0, time_t= 0, tpow=0, npw1=0, npw2=0,
257 # frame_cnt=0, time_t= 0, tpow=0, npw1=0, npw2=0,
258 # cpw1=0, pcw2=0, ps_err=0, te_err=0, rc_err=0, grs1=0,
258 # cpw1=0, pcw2=0, ps_err=0, te_err=0, rc_err=0, grs1=0,
259 # grs2=0, azipos=0, azivel=0, elvpos=0, elvvel=0, northangle=0,
259 # grs2=0, azipos=0, azivel=0, elvpos=0, elvvel=0, northangle=0,
260 # microsec=0, azisetvel=0, elvsetpos=0, RadarConst=0
260 # microsec=0, azisetvel=0, elvsetpos=0, RadarConst=0
261
261
262
262
263 frame_cnt = frame_cnt
263 frame_cnt = frame_cnt
264 dwell = time_t
264 dwell = time_t
265 tpow = tpow
265 tpow = tpow
266 npw1 = npw1
266 npw1 = npw1
267 npw2 = npw2
267 npw2 = npw2
268 cpw1 = cpw1
268 cpw1 = cpw1
269 pcw2 = pcw2
269 pcw2 = pcw2
270 ps_err = ps_err
270 ps_err = ps_err
271 te_err = te_err
271 te_err = te_err
272 rc_err = rc_err
272 rc_err = rc_err
273 grs1 = grs1
273 grs1 = grs1
274 grs2 = grs2
274 grs2 = grs2
275 azipos = azipos
275 azipos = azipos
276 azivel = azivel
276 azivel = azivel
277 elvpos = elvpos
277 elvpos = elvpos
278 elvvel = elvvel
278 elvvel = elvvel
279 northAngle = northAngle
279 northAngle = northAngle
280 microsec = microsec
280 microsec = microsec
281 azisetvel = azisetvel
281 azisetvel = azisetvel
282 elvsetpos = elvsetpos
282 elvsetpos = elvsetpos
283 RadarConst5 = RadarConst
283 RadarConst5 = RadarConst
284
284
285
285
286 # print fp
286 # print fp
287 # startFp = open('/home/erick/Documents/Data/huancayo.20161019.22.fdt',"rb") #The method tell() returns the current position of the file read/write pointer within the file.
287 # startFp = open('/home/erick/Documents/Data/huancayo.20161019.22.fdt',"rb") #The method tell() returns the current position of the file read/write pointer within the file.
288 # startFp = open(fp,"rb") #The method tell() returns the current position of the file read/write pointer within the file.
288 # startFp = open(fp,"rb") #The method tell() returns the current position of the file read/write pointer within the file.
289 # RecCounter=0
289 # RecCounter=0
290 # Off2StartNxtRec=811248
290 # Off2StartNxtRec=811248
291 # print 'OffsetStartHeader ',self.OffsetStartHeader,'RecCounter ', self.RecCounter, 'Off2StartNxtRec ' , self.Off2StartNxtRec
291 # print 'OffsetStartHeader ',self.OffsetStartHeader,'RecCounter ', self.RecCounter, 'Off2StartNxtRec ' , self.Off2StartNxtRec
292 #OffRHeader= self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec
292 #OffRHeader= self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec
293 #startFp.seek(OffRHeader, os.SEEK_SET)
293 #startFp.seek(OffRHeader, os.SEEK_SET)
294 print 'debe ser 48, RecCounter*811248', self.OffsetStartHeader, self.RecCounter, self.Off2StartNxtRec
294 print('debe ser 48, RecCounter*811248', self.OffsetStartHeader, self.RecCounter, self.Off2StartNxtRec)
295 print 'Posicion del bloque: ', OffRHeader
295 print('Posicion del bloque: ', OffRHeader)
296
296
297 header = numpy.fromfile(startFp, SRVI_STRUCTURE, 1)
297 header = numpy.fromfile(startFp, SRVI_STRUCTURE, 1)
298
298
299 self.frame_cnt = header['frame_cnt'][0]
299 self.frame_cnt = header['frame_cnt'][0]
300 self.time_t = header['frame_cnt'][0] #
300 self.time_t = header['frame_cnt'][0] #
301 self.tpow = header['frame_cnt'][0] #
301 self.tpow = header['frame_cnt'][0] #
302 self.npw1 = header['frame_cnt'][0] #
302 self.npw1 = header['frame_cnt'][0] #
303 self.npw2 = header['frame_cnt'][0] #
303 self.npw2 = header['frame_cnt'][0] #
304 self.cpw1 = header['frame_cnt'][0] #
304 self.cpw1 = header['frame_cnt'][0] #
305 self.pcw2 = header['frame_cnt'][0] #
305 self.pcw2 = header['frame_cnt'][0] #
306 self.ps_err = header['frame_cnt'][0] #
306 self.ps_err = header['frame_cnt'][0] #
307 self.te_err = header['frame_cnt'][0] #
307 self.te_err = header['frame_cnt'][0] #
308 self.rc_err = header['frame_cnt'][0] #
308 self.rc_err = header['frame_cnt'][0] #
309 self.grs1 = header['frame_cnt'][0] #
309 self.grs1 = header['frame_cnt'][0] #
310 self.grs2 = header['frame_cnt'][0] #
310 self.grs2 = header['frame_cnt'][0] #
311 self.azipos = header['frame_cnt'][0] #
311 self.azipos = header['frame_cnt'][0] #
312 self.azivel = header['frame_cnt'][0] #
312 self.azivel = header['frame_cnt'][0] #
313 self.elvpos = header['frame_cnt'][0] #
313 self.elvpos = header['frame_cnt'][0] #
314 self.elvvel = header['frame_cnt'][0] #
314 self.elvvel = header['frame_cnt'][0] #
315 self.northAngle = header['frame_cnt'][0] #
315 self.northAngle = header['frame_cnt'][0] #
316 self.microsec = header['frame_cnt'][0] #
316 self.microsec = header['frame_cnt'][0] #
317 self.azisetvel = header['frame_cnt'][0] #
317 self.azisetvel = header['frame_cnt'][0] #
318 self.elvsetpos = header['frame_cnt'][0] #
318 self.elvsetpos = header['frame_cnt'][0] #
319 self.RadarConst = header['frame_cnt'][0] #
319 self.RadarConst = header['frame_cnt'][0] #
320
320
321
321
322 self.ipp = 0.5 * (SPEED_OF_LIGHT / self.PRFhz)
322 self.ipp = 0.5 * (SPEED_OF_LIGHT / self.PRFhz)
323
323
324 self.RHsize = 180 + 20 * self.nChannels
324 self.RHsize = 180 + 20 * self.nChannels
325 self.Datasize = self.nProfiles * self.nChannels * self.nHeights * 2 * 4
325 self.Datasize = self.nProfiles * self.nChannels * self.nHeights * 2 * 4
326 # print 'Datasize',self.Datasize
326 # print 'Datasize',self.Datasize
327 endFp = self.OffsetStartHeader + self.RecCounter * self.Off2StartNxtRec
327 endFp = self.OffsetStartHeader + self.RecCounter * self.Off2StartNxtRec
328
328
329 print '=============================================='
329 print('==============================================')
330
330
331 print '=============================================='
331 print('==============================================') No newline at end of file
@@ -1,23 +1,23
1 '''
1 '''
2
2
3 $Author: murco $
3 $Author: murco $
4 $Id: JRODataIO.py 169 2012-11-19 21:57:03Z murco $
4 $Id: JRODataIO.py 169 2012-11-19 21:57:03Z murco $
5 '''
5 '''
6
6
7 from jroIO_voltage import *
7 from .jroIO_voltage import *
8 from jroIO_spectra import *
8 from .jroIO_spectra import *
9 from jroIO_heispectra import *
9 from .jroIO_heispectra import *
10 from jroIO_usrp import *
10 from .jroIO_usrp import *
11 from jroIO_digitalRF import *
11 from .jroIO_digitalRF import *
12 from jroIO_kamisr import *
12 from .jroIO_kamisr import *
13 from jroIO_param import *
13 from .jroIO_param import *
14 from jroIO_hf import *
14 from .jroIO_hf import *
15
15
16 from jroIO_madrigal import *
16 from .jroIO_madrigal import *
17
17
18 from bltrIO_param import *
18 from .bltrIO_param import *
19 from jroIO_bltr import *
19 from .jroIO_bltr import *
20 from jroIO_mira35c import *
20 from .jroIO_mira35c import *
21 from julIO_param import *
21 from .julIO_param import *
22
22
23 from pxIO_param import * No newline at end of file
23 from .pxIO_param import * No newline at end of file
@@ -1,369 +1,369
1 '''
1 '''
2 Created on Nov 9, 2016
2 Created on Nov 9, 2016
3
3
4 @author: roj- LouVD
4 @author: roj- LouVD
5 '''
5 '''
6
6
7
7
8 import os
8 import os
9 import sys
9 import sys
10 import time
10 import time
11 import glob
11 import glob
12 import datetime
12 import datetime
13
13
14 import numpy
14 import numpy
15
15
16 from schainpy.model.proc.jroproc_base import ProcessingUnit
16 from schainpy.model.proc.jroproc_base import ProcessingUnit
17 from schainpy.model.data.jrodata import Parameters
17 from schainpy.model.data.jrodata import Parameters
18 from schainpy.model.io.jroIO_base import JRODataReader, isNumber
18 from schainpy.model.io.jroIO_base import JRODataReader, isNumber
19 from schainpy.utils import log
19 from schainpy.utils import log
20
20
21 FILE_HEADER_STRUCTURE = numpy.dtype([
21 FILE_HEADER_STRUCTURE = numpy.dtype([
22 ('FMN', '<u4'),
22 ('FMN', '<u4'),
23 ('nrec', '<u4'),
23 ('nrec', '<u4'),
24 ('fr_offset', '<u4'),
24 ('fr_offset', '<u4'),
25 ('id', '<u4'),
25 ('id', '<u4'),
26 ('site', 'u1', (32,))
26 ('site', 'u1', (32,))
27 ])
27 ])
28
28
29 REC_HEADER_STRUCTURE = numpy.dtype([
29 REC_HEADER_STRUCTURE = numpy.dtype([
30 ('rmn', '<u4'),
30 ('rmn', '<u4'),
31 ('rcounter', '<u4'),
31 ('rcounter', '<u4'),
32 ('nr_offset', '<u4'),
32 ('nr_offset', '<u4'),
33 ('tr_offset', '<u4'),
33 ('tr_offset', '<u4'),
34 ('time', '<u4'),
34 ('time', '<u4'),
35 ('time_msec', '<u4'),
35 ('time_msec', '<u4'),
36 ('tag', 'u1', (32,)),
36 ('tag', 'u1', (32,)),
37 ('comments', 'u1', (32,)),
37 ('comments', 'u1', (32,)),
38 ('lat', '<f4'),
38 ('lat', '<f4'),
39 ('lon', '<f4'),
39 ('lon', '<f4'),
40 ('gps_status', '<u4'),
40 ('gps_status', '<u4'),
41 ('freq', '<u4'),
41 ('freq', '<u4'),
42 ('freq0', '<u4'),
42 ('freq0', '<u4'),
43 ('nchan', '<u4'),
43 ('nchan', '<u4'),
44 ('delta_r', '<u4'),
44 ('delta_r', '<u4'),
45 ('nranges', '<u4'),
45 ('nranges', '<u4'),
46 ('r0', '<u4'),
46 ('r0', '<u4'),
47 ('prf', '<u4'),
47 ('prf', '<u4'),
48 ('ncoh', '<u4'),
48 ('ncoh', '<u4'),
49 ('npoints', '<u4'),
49 ('npoints', '<u4'),
50 ('polarization', '<i4'),
50 ('polarization', '<i4'),
51 ('rx_filter', '<u4'),
51 ('rx_filter', '<u4'),
52 ('nmodes', '<u4'),
52 ('nmodes', '<u4'),
53 ('dmode_index', '<u4'),
53 ('dmode_index', '<u4'),
54 ('dmode_rngcorr', '<u4'),
54 ('dmode_rngcorr', '<u4'),
55 ('nrxs', '<u4'),
55 ('nrxs', '<u4'),
56 ('acf_length', '<u4'),
56 ('acf_length', '<u4'),
57 ('acf_lags', '<u4'),
57 ('acf_lags', '<u4'),
58 ('sea_to_atmos', '<f4'),
58 ('sea_to_atmos', '<f4'),
59 ('sea_notch', '<u4'),
59 ('sea_notch', '<u4'),
60 ('lh_sea', '<u4'),
60 ('lh_sea', '<u4'),
61 ('hh_sea', '<u4'),
61 ('hh_sea', '<u4'),
62 ('nbins_sea', '<u4'),
62 ('nbins_sea', '<u4'),
63 ('min_snr', '<f4'),
63 ('min_snr', '<f4'),
64 ('min_cc', '<f4'),
64 ('min_cc', '<f4'),
65 ('max_time_diff', '<f4')
65 ('max_time_diff', '<f4')
66 ])
66 ])
67
67
68 DATA_STRUCTURE = numpy.dtype([
68 DATA_STRUCTURE = numpy.dtype([
69 ('range', '<u4'),
69 ('range', '<u4'),
70 ('status', '<u4'),
70 ('status', '<u4'),
71 ('zonal', '<f4'),
71 ('zonal', '<f4'),
72 ('meridional', '<f4'),
72 ('meridional', '<f4'),
73 ('vertical', '<f4'),
73 ('vertical', '<f4'),
74 ('zonal_a', '<f4'),
74 ('zonal_a', '<f4'),
75 ('meridional_a', '<f4'),
75 ('meridional_a', '<f4'),
76 ('corrected_fading', '<f4'), # seconds
76 ('corrected_fading', '<f4'), # seconds
77 ('uncorrected_fading', '<f4'), # seconds
77 ('uncorrected_fading', '<f4'), # seconds
78 ('time_diff', '<f4'),
78 ('time_diff', '<f4'),
79 ('major_axis', '<f4'),
79 ('major_axis', '<f4'),
80 ('axial_ratio', '<f4'),
80 ('axial_ratio', '<f4'),
81 ('orientation', '<f4'),
81 ('orientation', '<f4'),
82 ('sea_power', '<u4'),
82 ('sea_power', '<u4'),
83 ('sea_algorithm', '<u4')
83 ('sea_algorithm', '<u4')
84 ])
84 ])
85
85
86
86
87 class BLTRParamReader(JRODataReader, ProcessingUnit):
87 class BLTRParamReader(JRODataReader, ProcessingUnit):
88 '''
88 '''
89 Boundary Layer and Tropospheric Radar (BLTR) reader, Wind velocities and SNR from *.sswma files
89 Boundary Layer and Tropospheric Radar (BLTR) reader, Wind velocities and SNR from *.sswma files
90 '''
90 '''
91
91
92 ext = '.sswma'
92 ext = '.sswma'
93
93
94 def __init__(self, **kwargs):
94 def __init__(self, **kwargs):
95
95
96 ProcessingUnit.__init__(self, **kwargs)
96 ProcessingUnit.__init__(self, **kwargs)
97
97
98 self.dataOut = Parameters()
98 self.dataOut = Parameters()
99 self.counter_records = 0
99 self.counter_records = 0
100 self.flagNoMoreFiles = 0
100 self.flagNoMoreFiles = 0
101 self.isConfig = False
101 self.isConfig = False
102 self.filename = None
102 self.filename = None
103
103
104 def setup(self,
104 def setup(self,
105 path=None,
105 path=None,
106 startDate=None,
106 startDate=None,
107 endDate=None,
107 endDate=None,
108 ext=None,
108 ext=None,
109 startTime=datetime.time(0, 0, 0),
109 startTime=datetime.time(0, 0, 0),
110 endTime=datetime.time(23, 59, 59),
110 endTime=datetime.time(23, 59, 59),
111 timezone=0,
111 timezone=0,
112 status_value=0,
112 status_value=0,
113 **kwargs):
113 **kwargs):
114
114
115 self.path = path
115 self.path = path
116 self.startDate = startDate
116 self.startDate = startDate
117 self.endDate = endDate
117 self.endDate = endDate
118 self.startTime = startTime
118 self.startTime = startTime
119 self.endTime = endTime
119 self.endTime = endTime
120 self.status_value = status_value
120 self.status_value = status_value
121 self.datatime = datetime.datetime(1900,1,1)
121 self.datatime = datetime.datetime(1900,1,1)
122
122
123 if self.path is None:
123 if self.path is None:
124 raise ValueError, "The path is not valid"
124 raise ValueError("The path is not valid")
125
125
126 if ext is None:
126 if ext is None:
127 ext = self.ext
127 ext = self.ext
128
128
129 self.search_files(self.path, startDate, endDate, ext)
129 self.search_files(self.path, startDate, endDate, ext)
130 self.timezone = timezone
130 self.timezone = timezone
131 self.fileIndex = 0
131 self.fileIndex = 0
132
132
133 if not self.fileList:
133 if not self.fileList:
134 raise Warning, "There is no files matching these date in the folder: %s. \n Check 'startDate' and 'endDate' " % (
134 raise Warning("There is no files matching these date in the folder: %s. \n Check 'startDate' and 'endDate' " % (
135 path)
135 path))
136
136
137 self.setNextFile()
137 self.setNextFile()
138
138
139 def search_files(self, path, startDate, endDate, ext):
139 def search_files(self, path, startDate, endDate, ext):
140 '''
140 '''
141 Searching for BLTR rawdata file in path
141 Searching for BLTR rawdata file in path
142 Creating a list of file to proces included in [startDate,endDate]
142 Creating a list of file to proces included in [startDate,endDate]
143
143
144 Input:
144 Input:
145 path - Path to find BLTR rawdata files
145 path - Path to find BLTR rawdata files
146 startDate - Select file from this date
146 startDate - Select file from this date
147 enDate - Select file until this date
147 enDate - Select file until this date
148 ext - Extension of the file to read
148 ext - Extension of the file to read
149 '''
149 '''
150
150
151 log.success('Searching files in {} '.format(path), 'BLTRParamReader')
151 log.success('Searching files in {} '.format(path), 'BLTRParamReader')
152 foldercounter = 0
152 foldercounter = 0
153 fileList0 = glob.glob1(path, "*%s" % ext)
153 fileList0 = glob.glob1(path, "*%s" % ext)
154 fileList0.sort()
154 fileList0.sort()
155
155
156 self.fileList = []
156 self.fileList = []
157 self.dateFileList = []
157 self.dateFileList = []
158
158
159 for thisFile in fileList0:
159 for thisFile in fileList0:
160 year = thisFile[-14:-10]
160 year = thisFile[-14:-10]
161 if not isNumber(year):
161 if not isNumber(year):
162 continue
162 continue
163
163
164 month = thisFile[-10:-8]
164 month = thisFile[-10:-8]
165 if not isNumber(month):
165 if not isNumber(month):
166 continue
166 continue
167
167
168 day = thisFile[-8:-6]
168 day = thisFile[-8:-6]
169 if not isNumber(day):
169 if not isNumber(day):
170 continue
170 continue
171
171
172 year, month, day = int(year), int(month), int(day)
172 year, month, day = int(year), int(month), int(day)
173 dateFile = datetime.date(year, month, day)
173 dateFile = datetime.date(year, month, day)
174
174
175 if (startDate > dateFile) or (endDate < dateFile):
175 if (startDate > dateFile) or (endDate < dateFile):
176 continue
176 continue
177
177
178 self.fileList.append(thisFile)
178 self.fileList.append(thisFile)
179 self.dateFileList.append(dateFile)
179 self.dateFileList.append(dateFile)
180
180
181 return
181 return
182
182
183 def setNextFile(self):
183 def setNextFile(self):
184
184
185 file_id = self.fileIndex
185 file_id = self.fileIndex
186
186
187 if file_id == len(self.fileList):
187 if file_id == len(self.fileList):
188 log.success('No more files in the folder', 'BLTRParamReader')
188 log.success('No more files in the folder', 'BLTRParamReader')
189 self.flagNoMoreFiles = 1
189 self.flagNoMoreFiles = 1
190 return 0
190 return 0
191
191
192 log.success('Opening {}'.format(self.fileList[file_id]), 'BLTRParamReader')
192 log.success('Opening {}'.format(self.fileList[file_id]), 'BLTRParamReader')
193 filename = os.path.join(self.path, self.fileList[file_id])
193 filename = os.path.join(self.path, self.fileList[file_id])
194
194
195 dirname, name = os.path.split(filename)
195 dirname, name = os.path.split(filename)
196 # 'peru2' ---> Piura - 'peru1' ---> Huancayo or Porcuya
196 # 'peru2' ---> Piura - 'peru1' ---> Huancayo or Porcuya
197 self.siteFile = name.split('.')[0]
197 self.siteFile = name.split('.')[0]
198 if self.filename is not None:
198 if self.filename is not None:
199 self.fp.close()
199 self.fp.close()
200 self.filename = filename
200 self.filename = filename
201 self.fp = open(self.filename, 'rb')
201 self.fp = open(self.filename, 'rb')
202 self.header_file = numpy.fromfile(self.fp, FILE_HEADER_STRUCTURE, 1)
202 self.header_file = numpy.fromfile(self.fp, FILE_HEADER_STRUCTURE, 1)
203 self.nrecords = self.header_file['nrec'][0]
203 self.nrecords = self.header_file['nrec'][0]
204 self.sizeOfFile = os.path.getsize(self.filename)
204 self.sizeOfFile = os.path.getsize(self.filename)
205 self.counter_records = 0
205 self.counter_records = 0
206 self.flagIsNewFile = 0
206 self.flagIsNewFile = 0
207 self.fileIndex += 1
207 self.fileIndex += 1
208
208
209 return 1
209 return 1
210
210
211 def readNextBlock(self):
211 def readNextBlock(self):
212
212
213 while True:
213 while True:
214 if self.counter_records == self.nrecords:
214 if self.counter_records == self.nrecords:
215 self.flagIsNewFile = 1
215 self.flagIsNewFile = 1
216 if not self.setNextFile():
216 if not self.setNextFile():
217 return 0
217 return 0
218
218
219 self.readBlock()
219 self.readBlock()
220
220
221 if (self.datatime < datetime.datetime.combine(self.startDate, self.startTime)) or \
221 if (self.datatime < datetime.datetime.combine(self.startDate, self.startTime)) or \
222 (self.datatime > datetime.datetime.combine(self.endDate, self.endTime)):
222 (self.datatime > datetime.datetime.combine(self.endDate, self.endTime)):
223 log.warning(
223 log.warning(
224 'Reading Record No. {}/{} -> {} [Skipping]'.format(
224 'Reading Record No. {}/{} -> {} [Skipping]'.format(
225 self.counter_records,
225 self.counter_records,
226 self.nrecords,
226 self.nrecords,
227 self.datatime.ctime()),
227 self.datatime.ctime()),
228 'BLTRParamReader')
228 'BLTRParamReader')
229 continue
229 continue
230 break
230 break
231
231
232 log.log('Reading Record No. {}/{} -> {}'.format(
232 log.log('Reading Record No. {}/{} -> {}'.format(
233 self.counter_records,
233 self.counter_records,
234 self.nrecords,
234 self.nrecords,
235 self.datatime.ctime()), 'BLTRParamReader')
235 self.datatime.ctime()), 'BLTRParamReader')
236
236
237 return 1
237 return 1
238
238
239 def readBlock(self):
239 def readBlock(self):
240
240
241 pointer = self.fp.tell()
241 pointer = self.fp.tell()
242 header_rec = numpy.fromfile(self.fp, REC_HEADER_STRUCTURE, 1)
242 header_rec = numpy.fromfile(self.fp, REC_HEADER_STRUCTURE, 1)
243 self.nchannels = header_rec['nchan'][0] / 2
243 self.nchannels = header_rec['nchan'][0] / 2
244 self.kchan = header_rec['nrxs'][0]
244 self.kchan = header_rec['nrxs'][0]
245 self.nmodes = header_rec['nmodes'][0]
245 self.nmodes = header_rec['nmodes'][0]
246 self.nranges = header_rec['nranges'][0]
246 self.nranges = header_rec['nranges'][0]
247 self.fp.seek(pointer)
247 self.fp.seek(pointer)
248 self.height = numpy.empty((self.nmodes, self.nranges))
248 self.height = numpy.empty((self.nmodes, self.nranges))
249 self.snr = numpy.empty((self.nmodes, self.nchannels, self.nranges))
249 self.snr = numpy.empty((self.nmodes, self.nchannels, self.nranges))
250 self.buffer = numpy.empty((self.nmodes, 3, self.nranges))
250 self.buffer = numpy.empty((self.nmodes, 3, self.nranges))
251 self.flagDiscontinuousBlock = 0
251 self.flagDiscontinuousBlock = 0
252
252
253 for mode in range(self.nmodes):
253 for mode in range(self.nmodes):
254 self.readHeader()
254 self.readHeader()
255 data = self.readData()
255 data = self.readData()
256 self.height[mode] = (data[0] - self.correction) / 1000.
256 self.height[mode] = (data[0] - self.correction) / 1000.
257 self.buffer[mode] = data[1]
257 self.buffer[mode] = data[1]
258 self.snr[mode] = data[2]
258 self.snr[mode] = data[2]
259
259
260 self.counter_records = self.counter_records + self.nmodes
260 self.counter_records = self.counter_records + self.nmodes
261
261
262 return
262 return
263
263
264 def readHeader(self):
264 def readHeader(self):
265 '''
265 '''
266 RecordHeader of BLTR rawdata file
266 RecordHeader of BLTR rawdata file
267 '''
267 '''
268
268
269 header_structure = numpy.dtype(
269 header_structure = numpy.dtype(
270 REC_HEADER_STRUCTURE.descr + [
270 REC_HEADER_STRUCTURE.descr + [
271 ('antenna_coord', 'f4', (2, self.nchannels)),
271 ('antenna_coord', 'f4', (2, self.nchannels)),
272 ('rx_gains', 'u4', (self.nchannels,)),
272 ('rx_gains', 'u4', (self.nchannels,)),
273 ('rx_analysis', 'u4', (self.nchannels,))
273 ('rx_analysis', 'u4', (self.nchannels,))
274 ]
274 ]
275 )
275 )
276
276
277 self.header_rec = numpy.fromfile(self.fp, header_structure, 1)
277 self.header_rec = numpy.fromfile(self.fp, header_structure, 1)
278 self.lat = self.header_rec['lat'][0]
278 self.lat = self.header_rec['lat'][0]
279 self.lon = self.header_rec['lon'][0]
279 self.lon = self.header_rec['lon'][0]
280 self.delta = self.header_rec['delta_r'][0]
280 self.delta = self.header_rec['delta_r'][0]
281 self.correction = self.header_rec['dmode_rngcorr'][0]
281 self.correction = self.header_rec['dmode_rngcorr'][0]
282 self.imode = self.header_rec['dmode_index'][0]
282 self.imode = self.header_rec['dmode_index'][0]
283 self.antenna = self.header_rec['antenna_coord']
283 self.antenna = self.header_rec['antenna_coord']
284 self.rx_gains = self.header_rec['rx_gains']
284 self.rx_gains = self.header_rec['rx_gains']
285 self.time = self.header_rec['time'][0]
285 self.time = self.header_rec['time'][0]
286 dt = datetime.datetime.utcfromtimestamp(self.time)
286 dt = datetime.datetime.utcfromtimestamp(self.time)
287 if dt.date()>self.datatime.date():
287 if dt.date()>self.datatime.date():
288 self.flagDiscontinuousBlock = 1
288 self.flagDiscontinuousBlock = 1
289 self.datatime = dt
289 self.datatime = dt
290
290
291 def readData(self):
291 def readData(self):
292 '''
292 '''
293 Reading and filtering data block record of BLTR rawdata file, filtering is according to status_value.
293 Reading and filtering data block record of BLTR rawdata file, filtering is according to status_value.
294
294
295 Input:
295 Input:
296 status_value - Array data is set to NAN for values that are not equal to status_value
296 status_value - Array data is set to NAN for values that are not equal to status_value
297
297
298 '''
298 '''
299
299
300 data_structure = numpy.dtype(
300 data_structure = numpy.dtype(
301 DATA_STRUCTURE.descr + [
301 DATA_STRUCTURE.descr + [
302 ('rx_saturation', 'u4', (self.nchannels,)),
302 ('rx_saturation', 'u4', (self.nchannels,)),
303 ('chan_offset', 'u4', (2 * self.nchannels,)),
303 ('chan_offset', 'u4', (2 * self.nchannels,)),
304 ('rx_amp', 'u4', (self.nchannels,)),
304 ('rx_amp', 'u4', (self.nchannels,)),
305 ('rx_snr', 'f4', (self.nchannels,)),
305 ('rx_snr', 'f4', (self.nchannels,)),
306 ('cross_snr', 'f4', (self.kchan,)),
306 ('cross_snr', 'f4', (self.kchan,)),
307 ('sea_power_relative', 'f4', (self.kchan,))]
307 ('sea_power_relative', 'f4', (self.kchan,))]
308 )
308 )
309
309
310 data = numpy.fromfile(self.fp, data_structure, self.nranges)
310 data = numpy.fromfile(self.fp, data_structure, self.nranges)
311
311
312 height = data['range']
312 height = data['range']
313 winds = numpy.array(
313 winds = numpy.array(
314 (data['zonal'], data['meridional'], data['vertical']))
314 (data['zonal'], data['meridional'], data['vertical']))
315 snr = data['rx_snr'].T
315 snr = data['rx_snr'].T
316
316
317 winds[numpy.where(winds == -9999.)] = numpy.nan
317 winds[numpy.where(winds == -9999.)] = numpy.nan
318 winds[:, numpy.where(data['status'] != self.status_value)] = numpy.nan
318 winds[:, numpy.where(data['status'] != self.status_value)] = numpy.nan
319 snr[numpy.where(snr == -9999.)] = numpy.nan
319 snr[numpy.where(snr == -9999.)] = numpy.nan
320 snr[:, numpy.where(data['status'] != self.status_value)] = numpy.nan
320 snr[:, numpy.where(data['status'] != self.status_value)] = numpy.nan
321 snr = numpy.power(10, snr / 10)
321 snr = numpy.power(10, snr / 10)
322
322
323 return height, winds, snr
323 return height, winds, snr
324
324
325 def set_output(self):
325 def set_output(self):
326 '''
326 '''
327 Storing data from databuffer to dataOut object
327 Storing data from databuffer to dataOut object
328 '''
328 '''
329
329
330 self.dataOut.data_SNR = self.snr
330 self.dataOut.data_SNR = self.snr
331 self.dataOut.height = self.height
331 self.dataOut.height = self.height
332 self.dataOut.data = self.buffer
332 self.dataOut.data = self.buffer
333 self.dataOut.utctimeInit = self.time
333 self.dataOut.utctimeInit = self.time
334 self.dataOut.utctime = self.dataOut.utctimeInit
334 self.dataOut.utctime = self.dataOut.utctimeInit
335 self.dataOut.useLocalTime = False
335 self.dataOut.useLocalTime = False
336 self.dataOut.paramInterval = 157
336 self.dataOut.paramInterval = 157
337 self.dataOut.timezone = self.timezone
337 self.dataOut.timezone = self.timezone
338 self.dataOut.site = self.siteFile
338 self.dataOut.site = self.siteFile
339 self.dataOut.nrecords = self.nrecords / self.nmodes
339 self.dataOut.nrecords = self.nrecords / self.nmodes
340 self.dataOut.sizeOfFile = self.sizeOfFile
340 self.dataOut.sizeOfFile = self.sizeOfFile
341 self.dataOut.lat = self.lat
341 self.dataOut.lat = self.lat
342 self.dataOut.lon = self.lon
342 self.dataOut.lon = self.lon
343 self.dataOut.channelList = range(self.nchannels)
343 self.dataOut.channelList = list(range(self.nchannels))
344 self.dataOut.kchan = self.kchan
344 self.dataOut.kchan = self.kchan
345 self.dataOut.delta = self.delta
345 self.dataOut.delta = self.delta
346 self.dataOut.correction = self.correction
346 self.dataOut.correction = self.correction
347 self.dataOut.nmodes = self.nmodes
347 self.dataOut.nmodes = self.nmodes
348 self.dataOut.imode = self.imode
348 self.dataOut.imode = self.imode
349 self.dataOut.antenna = self.antenna
349 self.dataOut.antenna = self.antenna
350 self.dataOut.rx_gains = self.rx_gains
350 self.dataOut.rx_gains = self.rx_gains
351 self.dataOut.flagNoData = False
351 self.dataOut.flagNoData = False
352 self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock
352 self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock
353
353
354 def getData(self):
354 def getData(self):
355 '''
355 '''
356 Storing data from databuffer to dataOut object
356 Storing data from databuffer to dataOut object
357 '''
357 '''
358 if self.flagNoMoreFiles:
358 if self.flagNoMoreFiles:
359 self.dataOut.flagNoData = True
359 self.dataOut.flagNoData = True
360 log.success('No file left to process', 'BLTRParamReader')
360 log.success('No file left to process', 'BLTRParamReader')
361 return 0
361 return 0
362
362
363 if not self.readNextBlock():
363 if not self.readNextBlock():
364 self.dataOut.flagNoData = True
364 self.dataOut.flagNoData = True
365 return 0
365 return 0
366
366
367 self.set_output()
367 self.set_output()
368
368
369 return 1
369 return 1 No newline at end of file
@@ -1,692 +1,692
1 '''
1 '''
2 @author: Daniel Suarez
2 @author: Daniel Suarez
3 '''
3 '''
4
4
5 import os
5 import os
6 import sys
6 import sys
7 import glob
7 import glob
8 import fnmatch
8 import fnmatch
9 import datetime
9 import datetime
10 import time
10 import time
11 import re
11 import re
12 import h5py
12 import h5py
13 import numpy
13 import numpy
14
14
15 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
15 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
16 from schainpy.model.data.jroamisr import AMISR
16 from schainpy.model.data.jroamisr import AMISR
17
17
18 try:
18 try:
19 from gevent import sleep
19 from gevent import sleep
20 except:
20 except:
21 from time import sleep
21 from time import sleep
22
22
23 class RadacHeader():
23 class RadacHeader():
24 def __init__(self, fp):
24 def __init__(self, fp):
25 header = 'Raw11/Data/RadacHeader'
25 header = 'Raw11/Data/RadacHeader'
26 self.beamCodeByPulse = fp.get(header+'/BeamCode')
26 self.beamCodeByPulse = fp.get(header+'/BeamCode')
27 self.beamCode = fp.get('Raw11/Data/Beamcodes')
27 self.beamCode = fp.get('Raw11/Data/Beamcodes')
28 self.code = fp.get(header+'/Code')
28 self.code = fp.get(header+'/Code')
29 self.frameCount = fp.get(header+'/FrameCount')
29 self.frameCount = fp.get(header+'/FrameCount')
30 self.modeGroup = fp.get(header+'/ModeGroup')
30 self.modeGroup = fp.get(header+'/ModeGroup')
31 self.nsamplesPulse = fp.get(header+'/NSamplesPulse')
31 self.nsamplesPulse = fp.get(header+'/NSamplesPulse')
32 self.pulseCount = fp.get(header+'/PulseCount')
32 self.pulseCount = fp.get(header+'/PulseCount')
33 self.radacTime = fp.get(header+'/RadacTime')
33 self.radacTime = fp.get(header+'/RadacTime')
34 self.timeCount = fp.get(header+'/TimeCount')
34 self.timeCount = fp.get(header+'/TimeCount')
35 self.timeStatus = fp.get(header+'/TimeStatus')
35 self.timeStatus = fp.get(header+'/TimeStatus')
36
36
37 self.nrecords = self.pulseCount.shape[0] #nblocks
37 self.nrecords = self.pulseCount.shape[0] #nblocks
38 self.npulses = self.pulseCount.shape[1] #nprofile
38 self.npulses = self.pulseCount.shape[1] #nprofile
39 self.nsamples = self.nsamplesPulse[0,0] #ngates
39 self.nsamples = self.nsamplesPulse[0,0] #ngates
40 self.nbeams = self.beamCode.shape[1]
40 self.nbeams = self.beamCode.shape[1]
41
41
42
42
43 def getIndexRangeToPulse(self, idrecord=0):
43 def getIndexRangeToPulse(self, idrecord=0):
44 #indexToZero = numpy.where(self.pulseCount.value[idrecord,:]==0)
44 #indexToZero = numpy.where(self.pulseCount.value[idrecord,:]==0)
45 #startPulseCountId = indexToZero[0][0]
45 #startPulseCountId = indexToZero[0][0]
46 #endPulseCountId = startPulseCountId - 1
46 #endPulseCountId = startPulseCountId - 1
47 #range1 = numpy.arange(startPulseCountId,self.npulses,1)
47 #range1 = numpy.arange(startPulseCountId,self.npulses,1)
48 #range2 = numpy.arange(0,startPulseCountId,1)
48 #range2 = numpy.arange(0,startPulseCountId,1)
49 #return range1, range2
49 #return range1, range2
50 zero = 0
50 zero = 0
51 npulse = max(self.pulseCount[0,:]+1)-1
51 npulse = max(self.pulseCount[0,:]+1)-1
52 looking_index = numpy.where(self.pulseCount.value[idrecord,:]==npulse)[0]
52 looking_index = numpy.where(self.pulseCount.value[idrecord,:]==npulse)[0]
53 getLastIndex = looking_index[-1]
53 getLastIndex = looking_index[-1]
54 index_data = numpy.arange(0,getLastIndex+1,1)
54 index_data = numpy.arange(0,getLastIndex+1,1)
55 index_buffer = numpy.arange(getLastIndex+1,self.npulses,1)
55 index_buffer = numpy.arange(getLastIndex+1,self.npulses,1)
56 return index_data, index_buffer
56 return index_data, index_buffer
57
57
58 class AMISRReader(ProcessingUnit):
58 class AMISRReader(ProcessingUnit):
59
59
60 path = None
60 path = None
61 startDate = None
61 startDate = None
62 endDate = None
62 endDate = None
63 startTime = None
63 startTime = None
64 endTime = None
64 endTime = None
65 walk = None
65 walk = None
66 isConfig = False
66 isConfig = False
67
67
68 def __init__(self):
68 def __init__(self):
69 self.set = None
69 self.set = None
70 self.subset = None
70 self.subset = None
71 self.extension_file = '.h5'
71 self.extension_file = '.h5'
72 self.dtc_str = 'dtc'
72 self.dtc_str = 'dtc'
73 self.dtc_id = 0
73 self.dtc_id = 0
74 self.status = True
74 self.status = True
75 self.isConfig = False
75 self.isConfig = False
76 self.dirnameList = []
76 self.dirnameList = []
77 self.filenameList = []
77 self.filenameList = []
78 self.fileIndex = None
78 self.fileIndex = None
79 self.flagNoMoreFiles = False
79 self.flagNoMoreFiles = False
80 self.flagIsNewFile = 0
80 self.flagIsNewFile = 0
81 self.filename = ''
81 self.filename = ''
82 self.amisrFilePointer = None
82 self.amisrFilePointer = None
83 self.radacHeaderObj = None
83 self.radacHeaderObj = None
84 self.dataOut = self.__createObjByDefault()
84 self.dataOut = self.__createObjByDefault()
85 self.datablock = None
85 self.datablock = None
86 self.rest_datablock = None
86 self.rest_datablock = None
87 self.range = None
87 self.range = None
88 self.idrecord_count = 0
88 self.idrecord_count = 0
89 self.profileIndex = 0
89 self.profileIndex = 0
90 self.index_amisr_sample = None
90 self.index_amisr_sample = None
91 self.index_amisr_buffer = None
91 self.index_amisr_buffer = None
92 self.beamCodeByFrame = None
92 self.beamCodeByFrame = None
93 self.radacTimeByFrame = None
93 self.radacTimeByFrame = None
94 #atributos originales tal y como esta en el archivo de datos
94 #atributos originales tal y como esta en el archivo de datos
95 self.beamCodesFromFile = None
95 self.beamCodesFromFile = None
96 self.radacTimeFromFile = None
96 self.radacTimeFromFile = None
97 self.rangeFromFile = None
97 self.rangeFromFile = None
98 self.dataByFrame = None
98 self.dataByFrame = None
99 self.dataset = None
99 self.dataset = None
100
100
101 self.beamCodeDict = {}
101 self.beamCodeDict = {}
102 self.beamRangeDict = {}
102 self.beamRangeDict = {}
103
103
104 #experiment cgf file
104 #experiment cgf file
105 self.npulsesint_fromfile = None
105 self.npulsesint_fromfile = None
106 self.recordsperfile_fromfile = None
106 self.recordsperfile_fromfile = None
107 self.nbeamcodes_fromfile = None
107 self.nbeamcodes_fromfile = None
108 self.ngates_fromfile = None
108 self.ngates_fromfile = None
109 self.ippSeconds_fromfile = None
109 self.ippSeconds_fromfile = None
110 self.frequency_h5file = None
110 self.frequency_h5file = None
111
111
112
112
113 self.__firstFile = True
113 self.__firstFile = True
114 self.buffer_radactime = None
114 self.buffer_radactime = None
115
115
116 self.index4_schain_datablock = None
116 self.index4_schain_datablock = None
117 self.index4_buffer = None
117 self.index4_buffer = None
118 self.schain_datablock = None
118 self.schain_datablock = None
119 self.buffer = None
119 self.buffer = None
120 self.linear_pulseCount = None
120 self.linear_pulseCount = None
121 self.npulseByFrame = None
121 self.npulseByFrame = None
122 self.profileIndex_offset = None
122 self.profileIndex_offset = None
123 self.timezone = 'ut'
123 self.timezone = 'ut'
124
124
125 self.__waitForNewFile = 20
125 self.__waitForNewFile = 20
126 self.__filename_online = None
126 self.__filename_online = None
127
127
128 def __createObjByDefault(self):
128 def __createObjByDefault(self):
129
129
130 dataObj = AMISR()
130 dataObj = AMISR()
131
131
132 return dataObj
132 return dataObj
133
133
134 def __setParameters(self,path='', startDate='',endDate='',startTime='', endTime='', walk=''):
134 def __setParameters(self,path='', startDate='',endDate='',startTime='', endTime='', walk=''):
135 self.path = path
135 self.path = path
136 self.startDate = startDate
136 self.startDate = startDate
137 self.endDate = endDate
137 self.endDate = endDate
138 self.startTime = startTime
138 self.startTime = startTime
139 self.endTime = endTime
139 self.endTime = endTime
140 self.walk = walk
140 self.walk = walk
141
141
142 def __checkPath(self):
142 def __checkPath(self):
143 if os.path.exists(self.path):
143 if os.path.exists(self.path):
144 self.status = 1
144 self.status = 1
145 else:
145 else:
146 self.status = 0
146 self.status = 0
147 print 'Path:%s does not exists'%self.path
147 print('Path:%s does not exists'%self.path)
148
148
149 return
149 return
150
150
151 def __selDates(self, amisr_dirname_format):
151 def __selDates(self, amisr_dirname_format):
152 try:
152 try:
153 year = int(amisr_dirname_format[0:4])
153 year = int(amisr_dirname_format[0:4])
154 month = int(amisr_dirname_format[4:6])
154 month = int(amisr_dirname_format[4:6])
155 dom = int(amisr_dirname_format[6:8])
155 dom = int(amisr_dirname_format[6:8])
156 thisDate = datetime.date(year,month,dom)
156 thisDate = datetime.date(year,month,dom)
157
157
158 if (thisDate>=self.startDate and thisDate <= self.endDate):
158 if (thisDate>=self.startDate and thisDate <= self.endDate):
159 return amisr_dirname_format
159 return amisr_dirname_format
160 except:
160 except:
161 return None
161 return None
162
162
163 def __findDataForDates(self,online=False):
163 def __findDataForDates(self,online=False):
164
164
165
165
166
166
167 if not(self.status):
167 if not(self.status):
168 return None
168 return None
169
169
170 pat = '\d+.\d+'
170 pat = '\d+.\d+'
171 dirnameList = [re.search(pat,x) for x in os.listdir(self.path)]
171 dirnameList = [re.search(pat,x) for x in os.listdir(self.path)]
172 dirnameList = filter(lambda x:x!=None,dirnameList)
172 dirnameList = [x for x in dirnameList if x!=None]
173 dirnameList = [x.string for x in dirnameList]
173 dirnameList = [x.string for x in dirnameList]
174 if not(online):
174 if not(online):
175 dirnameList = [self.__selDates(x) for x in dirnameList]
175 dirnameList = [self.__selDates(x) for x in dirnameList]
176 dirnameList = filter(lambda x:x!=None,dirnameList)
176 dirnameList = [x for x in dirnameList if x!=None]
177 if len(dirnameList)>0:
177 if len(dirnameList)>0:
178 self.status = 1
178 self.status = 1
179 self.dirnameList = dirnameList
179 self.dirnameList = dirnameList
180 self.dirnameList.sort()
180 self.dirnameList.sort()
181 else:
181 else:
182 self.status = 0
182 self.status = 0
183 return None
183 return None
184
184
185 def __getTimeFromData(self):
185 def __getTimeFromData(self):
186 startDateTime_Reader = datetime.datetime.combine(self.startDate,self.startTime)
186 startDateTime_Reader = datetime.datetime.combine(self.startDate,self.startTime)
187 endDateTime_Reader = datetime.datetime.combine(self.endDate,self.endTime)
187 endDateTime_Reader = datetime.datetime.combine(self.endDate,self.endTime)
188
188
189 print 'Filtering Files from %s to %s'%(startDateTime_Reader, endDateTime_Reader)
189 print('Filtering Files from %s to %s'%(startDateTime_Reader, endDateTime_Reader))
190 print '........................................'
190 print('........................................')
191 filter_filenameList = []
191 filter_filenameList = []
192 self.filenameList.sort()
192 self.filenameList.sort()
193 for i in range(len(self.filenameList)-1):
193 for i in range(len(self.filenameList)-1):
194 filename = self.filenameList[i]
194 filename = self.filenameList[i]
195 fp = h5py.File(filename,'r')
195 fp = h5py.File(filename,'r')
196 time_str = fp.get('Time/RadacTimeString')
196 time_str = fp.get('Time/RadacTimeString')
197
197
198 startDateTimeStr_File = time_str[0][0].split('.')[0]
198 startDateTimeStr_File = time_str[0][0].split('.')[0]
199 junk = time.strptime(startDateTimeStr_File, '%Y-%m-%d %H:%M:%S')
199 junk = time.strptime(startDateTimeStr_File, '%Y-%m-%d %H:%M:%S')
200 startDateTime_File = datetime.datetime(junk.tm_year,junk.tm_mon,junk.tm_mday,junk.tm_hour, junk.tm_min, junk.tm_sec)
200 startDateTime_File = datetime.datetime(junk.tm_year,junk.tm_mon,junk.tm_mday,junk.tm_hour, junk.tm_min, junk.tm_sec)
201
201
202 endDateTimeStr_File = time_str[-1][-1].split('.')[0]
202 endDateTimeStr_File = time_str[-1][-1].split('.')[0]
203 junk = time.strptime(endDateTimeStr_File, '%Y-%m-%d %H:%M:%S')
203 junk = time.strptime(endDateTimeStr_File, '%Y-%m-%d %H:%M:%S')
204 endDateTime_File = datetime.datetime(junk.tm_year,junk.tm_mon,junk.tm_mday,junk.tm_hour, junk.tm_min, junk.tm_sec)
204 endDateTime_File = datetime.datetime(junk.tm_year,junk.tm_mon,junk.tm_mday,junk.tm_hour, junk.tm_min, junk.tm_sec)
205
205
206 fp.close()
206 fp.close()
207
207
208 if self.timezone == 'lt':
208 if self.timezone == 'lt':
209 startDateTime_File = startDateTime_File - datetime.timedelta(minutes = 300)
209 startDateTime_File = startDateTime_File - datetime.timedelta(minutes = 300)
210 endDateTime_File = endDateTime_File - datetime.timedelta(minutes = 300)
210 endDateTime_File = endDateTime_File - datetime.timedelta(minutes = 300)
211
211
212 if (endDateTime_File>=startDateTime_Reader and endDateTime_File<endDateTime_Reader):
212 if (endDateTime_File>=startDateTime_Reader and endDateTime_File<endDateTime_Reader):
213 #self.filenameList.remove(filename)
213 #self.filenameList.remove(filename)
214 filter_filenameList.append(filename)
214 filter_filenameList.append(filename)
215
215
216 filter_filenameList.sort()
216 filter_filenameList.sort()
217 self.filenameList = filter_filenameList
217 self.filenameList = filter_filenameList
218 return 1
218 return 1
219
219
220 def __filterByGlob1(self, dirName):
220 def __filterByGlob1(self, dirName):
221 filter_files = glob.glob1(dirName, '*.*%s'%self.extension_file)
221 filter_files = glob.glob1(dirName, '*.*%s'%self.extension_file)
222 filterDict = {}
222 filterDict = {}
223 filterDict.setdefault(dirName)
223 filterDict.setdefault(dirName)
224 filterDict[dirName] = filter_files
224 filterDict[dirName] = filter_files
225 return filterDict
225 return filterDict
226
226
227 def __getFilenameList(self, fileListInKeys, dirList):
227 def __getFilenameList(self, fileListInKeys, dirList):
228 for value in fileListInKeys:
228 for value in fileListInKeys:
229 dirName = value.keys()[0]
229 dirName = list(value.keys())[0]
230 for file in value[dirName]:
230 for file in value[dirName]:
231 filename = os.path.join(dirName, file)
231 filename = os.path.join(dirName, file)
232 self.filenameList.append(filename)
232 self.filenameList.append(filename)
233
233
234
234
235 def __selectDataForTimes(self, online=False):
235 def __selectDataForTimes(self, online=False):
236 #aun no esta implementado el filtro for tiempo
236 #aun no esta implementado el filtro for tiempo
237 if not(self.status):
237 if not(self.status):
238 return None
238 return None
239
239
240 dirList = [os.path.join(self.path,x) for x in self.dirnameList]
240 dirList = [os.path.join(self.path,x) for x in self.dirnameList]
241
241
242 fileListInKeys = [self.__filterByGlob1(x) for x in dirList]
242 fileListInKeys = [self.__filterByGlob1(x) for x in dirList]
243
243
244 self.__getFilenameList(fileListInKeys, dirList)
244 self.__getFilenameList(fileListInKeys, dirList)
245 if not(online):
245 if not(online):
246 #filtro por tiempo
246 #filtro por tiempo
247 if not(self.all):
247 if not(self.all):
248 self.__getTimeFromData()
248 self.__getTimeFromData()
249
249
250 if len(self.filenameList)>0:
250 if len(self.filenameList)>0:
251 self.status = 1
251 self.status = 1
252 self.filenameList.sort()
252 self.filenameList.sort()
253 else:
253 else:
254 self.status = 0
254 self.status = 0
255 return None
255 return None
256
256
257 else:
257 else:
258 #get the last file - 1
258 #get the last file - 1
259 self.filenameList = [self.filenameList[-2]]
259 self.filenameList = [self.filenameList[-2]]
260
260
261 new_dirnameList = []
261 new_dirnameList = []
262 for dirname in self.dirnameList:
262 for dirname in self.dirnameList:
263 junk = numpy.array([dirname in x for x in self.filenameList])
263 junk = numpy.array([dirname in x for x in self.filenameList])
264 junk_sum = junk.sum()
264 junk_sum = junk.sum()
265 if junk_sum > 0:
265 if junk_sum > 0:
266 new_dirnameList.append(dirname)
266 new_dirnameList.append(dirname)
267 self.dirnameList = new_dirnameList
267 self.dirnameList = new_dirnameList
268 return 1
268 return 1
269
269
270 def searchFilesOnLine(self,
270 def searchFilesOnLine(self,
271 path,
271 path,
272 walk=True):
272 walk=True):
273
273
274 startDate = datetime.datetime.utcnow().date()
274 startDate = datetime.datetime.utcnow().date()
275 endDate = datetime.datetime.utcnow().date()
275 endDate = datetime.datetime.utcnow().date()
276
276
277 self.__setParameters(path=path, startDate=startDate, endDate=endDate, walk=walk)
277 self.__setParameters(path=path, startDate=startDate, endDate=endDate, walk=walk)
278
278
279 self.__checkPath()
279 self.__checkPath()
280
280
281 self.__findDataForDates(online=True)
281 self.__findDataForDates(online=True)
282
282
283 self.dirnameList = [self.dirnameList[-1]]
283 self.dirnameList = [self.dirnameList[-1]]
284
284
285 self.__selectDataForTimes(online=True)
285 self.__selectDataForTimes(online=True)
286
286
287 return
287 return
288
288
289
289
290 def searchFilesOffLine(self,
290 def searchFilesOffLine(self,
291 path,
291 path,
292 startDate,
292 startDate,
293 endDate,
293 endDate,
294 startTime=datetime.time(0,0,0),
294 startTime=datetime.time(0,0,0),
295 endTime=datetime.time(23,59,59),
295 endTime=datetime.time(23,59,59),
296 walk=True):
296 walk=True):
297
297
298 self.__setParameters(path, startDate, endDate, startTime, endTime, walk)
298 self.__setParameters(path, startDate, endDate, startTime, endTime, walk)
299
299
300 self.__checkPath()
300 self.__checkPath()
301
301
302 self.__findDataForDates()
302 self.__findDataForDates()
303
303
304 self.__selectDataForTimes()
304 self.__selectDataForTimes()
305
305
306 for i in range(len(self.filenameList)):
306 for i in range(len(self.filenameList)):
307 print "%s" %(self.filenameList[i])
307 print("%s" %(self.filenameList[i]))
308
308
309 return
309 return
310
310
311 def __setNextFileOffline(self):
311 def __setNextFileOffline(self):
312 idFile = self.fileIndex
312 idFile = self.fileIndex
313
313
314 while (True):
314 while (True):
315 idFile += 1
315 idFile += 1
316 if not(idFile < len(self.filenameList)):
316 if not(idFile < len(self.filenameList)):
317 self.flagNoMoreFiles = 1
317 self.flagNoMoreFiles = 1
318 print "No more Files"
318 print("No more Files")
319 return 0
319 return 0
320
320
321 filename = self.filenameList[idFile]
321 filename = self.filenameList[idFile]
322
322
323 amisrFilePointer = h5py.File(filename,'r')
323 amisrFilePointer = h5py.File(filename,'r')
324
324
325 break
325 break
326
326
327 self.flagIsNewFile = 1
327 self.flagIsNewFile = 1
328 self.fileIndex = idFile
328 self.fileIndex = idFile
329 self.filename = filename
329 self.filename = filename
330
330
331 self.amisrFilePointer = amisrFilePointer
331 self.amisrFilePointer = amisrFilePointer
332
332
333 print "Setting the file: %s"%self.filename
333 print("Setting the file: %s"%self.filename)
334
334
335 return 1
335 return 1
336
336
337
337
338 def __setNextFileOnline(self):
338 def __setNextFileOnline(self):
339 filename = self.filenameList[0]
339 filename = self.filenameList[0]
340 if self.__filename_online != None:
340 if self.__filename_online != None:
341 self.__selectDataForTimes(online=True)
341 self.__selectDataForTimes(online=True)
342 filename = self.filenameList[0]
342 filename = self.filenameList[0]
343 while self.__filename_online == filename:
343 while self.__filename_online == filename:
344 print 'waiting %d seconds to get a new file...'%(self.__waitForNewFile)
344 print('waiting %d seconds to get a new file...'%(self.__waitForNewFile))
345 sleep(self.__waitForNewFile)
345 sleep(self.__waitForNewFile)
346 self.__selectDataForTimes(online=True)
346 self.__selectDataForTimes(online=True)
347 filename = self.filenameList[0]
347 filename = self.filenameList[0]
348
348
349 self.__filename_online = filename
349 self.__filename_online = filename
350
350
351 self.amisrFilePointer = h5py.File(filename,'r')
351 self.amisrFilePointer = h5py.File(filename,'r')
352 self.flagIsNewFile = 1
352 self.flagIsNewFile = 1
353 self.filename = filename
353 self.filename = filename
354 print "Setting the file: %s"%self.filename
354 print("Setting the file: %s"%self.filename)
355 return 1
355 return 1
356
356
357
357
358 def __readHeader(self):
358 def __readHeader(self):
359 self.radacHeaderObj = RadacHeader(self.amisrFilePointer)
359 self.radacHeaderObj = RadacHeader(self.amisrFilePointer)
360
360
361 #update values from experiment cfg file
361 #update values from experiment cfg file
362 if self.radacHeaderObj.nrecords == self.recordsperfile_fromfile:
362 if self.radacHeaderObj.nrecords == self.recordsperfile_fromfile:
363 self.radacHeaderObj.nrecords = self.recordsperfile_fromfile
363 self.radacHeaderObj.nrecords = self.recordsperfile_fromfile
364 self.radacHeaderObj.nbeams = self.nbeamcodes_fromfile
364 self.radacHeaderObj.nbeams = self.nbeamcodes_fromfile
365 self.radacHeaderObj.npulses = self.npulsesint_fromfile
365 self.radacHeaderObj.npulses = self.npulsesint_fromfile
366 self.radacHeaderObj.nsamples = self.ngates_fromfile
366 self.radacHeaderObj.nsamples = self.ngates_fromfile
367
367
368 #looking index list for data
368 #looking index list for data
369 start_index = self.radacHeaderObj.pulseCount[0,:][0]
369 start_index = self.radacHeaderObj.pulseCount[0,:][0]
370 end_index = self.radacHeaderObj.npulses
370 end_index = self.radacHeaderObj.npulses
371 range4data = range(start_index, end_index)
371 range4data = list(range(start_index, end_index))
372 self.index4_schain_datablock = numpy.array(range4data)
372 self.index4_schain_datablock = numpy.array(range4data)
373
373
374 buffer_start_index = 0
374 buffer_start_index = 0
375 buffer_end_index = self.radacHeaderObj.pulseCount[0,:][0]
375 buffer_end_index = self.radacHeaderObj.pulseCount[0,:][0]
376 range4buffer = range(buffer_start_index, buffer_end_index)
376 range4buffer = list(range(buffer_start_index, buffer_end_index))
377 self.index4_buffer = numpy.array(range4buffer)
377 self.index4_buffer = numpy.array(range4buffer)
378
378
379 self.linear_pulseCount = numpy.array(range4data + range4buffer)
379 self.linear_pulseCount = numpy.array(range4data + range4buffer)
380 self.npulseByFrame = max(self.radacHeaderObj.pulseCount[0,:]+1)
380 self.npulseByFrame = max(self.radacHeaderObj.pulseCount[0,:]+1)
381
381
382 #get tuning frequency
382 #get tuning frequency
383 frequency_h5file_dataset = self.amisrFilePointer.get('Rx'+'/TuningFrequency')
383 frequency_h5file_dataset = self.amisrFilePointer.get('Rx'+'/TuningFrequency')
384 self.frequency_h5file = frequency_h5file_dataset[0,0]
384 self.frequency_h5file = frequency_h5file_dataset[0,0]
385
385
386 self.flagIsNewFile = 1
386 self.flagIsNewFile = 1
387
387
388 def __getBeamCode(self):
388 def __getBeamCode(self):
389 self.beamCodeDict = {}
389 self.beamCodeDict = {}
390 self.beamRangeDict = {}
390 self.beamRangeDict = {}
391
391
392 beamCodeMap = self.amisrFilePointer.get('Setup/BeamcodeMap')
392 beamCodeMap = self.amisrFilePointer.get('Setup/BeamcodeMap')
393
393
394 for i in range(len(self.radacHeaderObj.beamCode[0,:])):
394 for i in range(len(self.radacHeaderObj.beamCode[0,:])):
395 self.beamCodeDict.setdefault(i)
395 self.beamCodeDict.setdefault(i)
396 self.beamRangeDict.setdefault(i)
396 self.beamRangeDict.setdefault(i)
397 beamcodeValue = self.radacHeaderObj.beamCode[0,i]
397 beamcodeValue = self.radacHeaderObj.beamCode[0,i]
398 beamcodeIndex = numpy.where(beamCodeMap[:,0] == beamcodeValue)[0][0]
398 beamcodeIndex = numpy.where(beamCodeMap[:,0] == beamcodeValue)[0][0]
399 x = beamCodeMap[beamcodeIndex][1]
399 x = beamCodeMap[beamcodeIndex][1]
400 y = beamCodeMap[beamcodeIndex][2]
400 y = beamCodeMap[beamcodeIndex][2]
401 z = beamCodeMap[beamcodeIndex][3]
401 z = beamCodeMap[beamcodeIndex][3]
402 self.beamCodeDict[i] = [beamcodeValue, x, y, z]
402 self.beamCodeDict[i] = [beamcodeValue, x, y, z]
403
403
404 just4record0 = self.radacHeaderObj.beamCodeByPulse[0,:]
404 just4record0 = self.radacHeaderObj.beamCodeByPulse[0,:]
405
405
406 for i in range(len(self.beamCodeDict.values())):
406 for i in range(len(list(self.beamCodeDict.values()))):
407 xx = numpy.where(just4record0==self.beamCodeDict.values()[i][0])
407 xx = numpy.where(just4record0==list(self.beamCodeDict.values())[i][0])
408 indexPulseByBeam = self.linear_pulseCount[xx[0]]
408 indexPulseByBeam = self.linear_pulseCount[xx[0]]
409 self.beamRangeDict[i] = indexPulseByBeam
409 self.beamRangeDict[i] = indexPulseByBeam
410
410
411 def __getExpParameters(self):
411 def __getExpParameters(self):
412 if not(self.status):
412 if not(self.status):
413 return None
413 return None
414
414
415 experimentCfgPath = os.path.join(self.path, self.dirnameList[0], 'Setup')
415 experimentCfgPath = os.path.join(self.path, self.dirnameList[0], 'Setup')
416
416
417 expFinder = glob.glob1(experimentCfgPath,'*.exp')
417 expFinder = glob.glob1(experimentCfgPath,'*.exp')
418 if len(expFinder)== 0:
418 if len(expFinder)== 0:
419 self.status = 0
419 self.status = 0
420 return None
420 return None
421
421
422 experimentFilename = os.path.join(experimentCfgPath,expFinder[0])
422 experimentFilename = os.path.join(experimentCfgPath,expFinder[0])
423
423
424 f = open(experimentFilename)
424 f = open(experimentFilename)
425 lines = f.readlines()
425 lines = f.readlines()
426 f.close()
426 f.close()
427
427
428 parmsList = ['npulsesint*','recordsperfile*','nbeamcodes*','ngates*']
428 parmsList = ['npulsesint*','recordsperfile*','nbeamcodes*','ngates*']
429 filterList = [fnmatch.filter(lines, x) for x in parmsList]
429 filterList = [fnmatch.filter(lines, x) for x in parmsList]
430
430
431
431
432 values = [re.sub(r'\D',"",x[0]) for x in filterList]
432 values = [re.sub(r'\D',"",x[0]) for x in filterList]
433
433
434 self.npulsesint_fromfile = int(values[0])
434 self.npulsesint_fromfile = int(values[0])
435 self.recordsperfile_fromfile = int(values[1])
435 self.recordsperfile_fromfile = int(values[1])
436 self.nbeamcodes_fromfile = int(values[2])
436 self.nbeamcodes_fromfile = int(values[2])
437 self.ngates_fromfile = int(values[3])
437 self.ngates_fromfile = int(values[3])
438
438
439 tufileFinder = fnmatch.filter(lines, 'tufile=*')
439 tufileFinder = fnmatch.filter(lines, 'tufile=*')
440 tufile = tufileFinder[0].split('=')[1].split('\n')[0]
440 tufile = tufileFinder[0].split('=')[1].split('\n')[0]
441 tufile = tufile.split('\r')[0]
441 tufile = tufile.split('\r')[0]
442 tufilename = os.path.join(experimentCfgPath,tufile)
442 tufilename = os.path.join(experimentCfgPath,tufile)
443
443
444 f = open(tufilename)
444 f = open(tufilename)
445 lines = f.readlines()
445 lines = f.readlines()
446 f.close()
446 f.close()
447 self.ippSeconds_fromfile = float(lines[1].split()[2])/1E6
447 self.ippSeconds_fromfile = float(lines[1].split()[2])/1E6
448
448
449
449
450 self.status = 1
450 self.status = 1
451
451
452 def __setIdsAndArrays(self):
452 def __setIdsAndArrays(self):
453 self.dataByFrame = self.__setDataByFrame()
453 self.dataByFrame = self.__setDataByFrame()
454 self.beamCodeByFrame = self.amisrFilePointer.get('Raw11/Data/RadacHeader/BeamCode').value[0, :]
454 self.beamCodeByFrame = self.amisrFilePointer.get('Raw11/Data/RadacHeader/BeamCode').value[0, :]
455 self.readRanges()
455 self.readRanges()
456 self.index_amisr_sample, self.index_amisr_buffer = self.radacHeaderObj.getIndexRangeToPulse(0)
456 self.index_amisr_sample, self.index_amisr_buffer = self.radacHeaderObj.getIndexRangeToPulse(0)
457 self.radacTimeByFrame = numpy.zeros(self.radacHeaderObj.npulses)
457 self.radacTimeByFrame = numpy.zeros(self.radacHeaderObj.npulses)
458 if len(self.index_amisr_buffer) > 0:
458 if len(self.index_amisr_buffer) > 0:
459 self.buffer_radactime = numpy.zeros_like(self.radacTimeByFrame)
459 self.buffer_radactime = numpy.zeros_like(self.radacTimeByFrame)
460
460
461
461
462 def __setNextFile(self,online=False):
462 def __setNextFile(self,online=False):
463
463
464 if not(online):
464 if not(online):
465 newFile = self.__setNextFileOffline()
465 newFile = self.__setNextFileOffline()
466 else:
466 else:
467 newFile = self.__setNextFileOnline()
467 newFile = self.__setNextFileOnline()
468
468
469 if not(newFile):
469 if not(newFile):
470 return 0
470 return 0
471
471
472 self.__readHeader()
472 self.__readHeader()
473
473
474 if self.__firstFile:
474 if self.__firstFile:
475 self.__setIdsAndArrays()
475 self.__setIdsAndArrays()
476 self.__firstFile = False
476 self.__firstFile = False
477
477
478 self.__getBeamCode()
478 self.__getBeamCode()
479 self.readDataBlock()
479 self.readDataBlock()
480
480
481
481
482 def setup(self,path=None,
482 def setup(self,path=None,
483 startDate=None,
483 startDate=None,
484 endDate=None,
484 endDate=None,
485 startTime=datetime.time(0,0,0),
485 startTime=datetime.time(0,0,0),
486 endTime=datetime.time(23,59,59),
486 endTime=datetime.time(23,59,59),
487 walk=True,
487 walk=True,
488 timezone='ut',
488 timezone='ut',
489 all=0,
489 all=0,
490 online=False):
490 online=False):
491
491
492 self.timezone = timezone
492 self.timezone = timezone
493 self.all = all
493 self.all = all
494 self.online = online
494 self.online = online
495 if not(online):
495 if not(online):
496 #Busqueda de archivos offline
496 #Busqueda de archivos offline
497 self.searchFilesOffLine(path, startDate, endDate, startTime, endTime, walk)
497 self.searchFilesOffLine(path, startDate, endDate, startTime, endTime, walk)
498 else:
498 else:
499 self.searchFilesOnLine(path, walk)
499 self.searchFilesOnLine(path, walk)
500
500
501 if not(self.filenameList):
501 if not(self.filenameList):
502 print "There is no files into the folder: %s"%(path)
502 print("There is no files into the folder: %s"%(path))
503
503
504 sys.exit(-1)
504 sys.exit(-1)
505
505
506 self.__getExpParameters()
506 self.__getExpParameters()
507
507
508 self.fileIndex = -1
508 self.fileIndex = -1
509
509
510 self.__setNextFile(online)
510 self.__setNextFile(online)
511
511
512 # first_beamcode = self.radacHeaderObj.beamCodeByPulse[0,0]
512 # first_beamcode = self.radacHeaderObj.beamCodeByPulse[0,0]
513 # index = numpy.where(self.radacHeaderObj.beamCodeByPulse[0,:]!=first_beamcode)[0][0]
513 # index = numpy.where(self.radacHeaderObj.beamCodeByPulse[0,:]!=first_beamcode)[0][0]
514 self.profileIndex_offset = self.radacHeaderObj.pulseCount[0,:][0]
514 self.profileIndex_offset = self.radacHeaderObj.pulseCount[0,:][0]
515 self.profileIndex = self.profileIndex_offset
515 self.profileIndex = self.profileIndex_offset
516
516
517 def readRanges(self):
517 def readRanges(self):
518 dataset = self.amisrFilePointer.get('Raw11/Data/Samples/Range')
518 dataset = self.amisrFilePointer.get('Raw11/Data/Samples/Range')
519
519
520 self.rangeFromFile = numpy.reshape(dataset.value,(-1))
520 self.rangeFromFile = numpy.reshape(dataset.value,(-1))
521 return self.rangeFromFile
521 return self.rangeFromFile
522
522
523
523
524 def readRadacTime(self,idrecord, range1, range2):
524 def readRadacTime(self,idrecord, range1, range2):
525 self.radacTimeFromFile = self.radacHeaderObj.radacTime.value
525 self.radacTimeFromFile = self.radacHeaderObj.radacTime.value
526
526
527 radacTimeByFrame = numpy.zeros((self.radacHeaderObj.npulses))
527 radacTimeByFrame = numpy.zeros((self.radacHeaderObj.npulses))
528 #radacTimeByFrame = dataset[idrecord - 1,range1]
528 #radacTimeByFrame = dataset[idrecord - 1,range1]
529 #radacTimeByFrame = dataset[idrecord,range2]
529 #radacTimeByFrame = dataset[idrecord,range2]
530
530
531 return radacTimeByFrame
531 return radacTimeByFrame
532
532
533 def readBeamCode(self, idrecord, range1, range2):
533 def readBeamCode(self, idrecord, range1, range2):
534 dataset = self.amisrFilePointer.get('Raw11/Data/RadacHeader/BeamCode')
534 dataset = self.amisrFilePointer.get('Raw11/Data/RadacHeader/BeamCode')
535 beamcodeByFrame = numpy.zeros((self.radacHeaderObj.npulses))
535 beamcodeByFrame = numpy.zeros((self.radacHeaderObj.npulses))
536 self.beamCodesFromFile = dataset.value
536 self.beamCodesFromFile = dataset.value
537
537
538 #beamcodeByFrame[range1] = dataset[idrecord - 1, range1]
538 #beamcodeByFrame[range1] = dataset[idrecord - 1, range1]
539 #beamcodeByFrame[range2] = dataset[idrecord, range2]
539 #beamcodeByFrame[range2] = dataset[idrecord, range2]
540 beamcodeByFrame[range1] = dataset[idrecord, range1]
540 beamcodeByFrame[range1] = dataset[idrecord, range1]
541 beamcodeByFrame[range2] = dataset[idrecord, range2]
541 beamcodeByFrame[range2] = dataset[idrecord, range2]
542
542
543 return beamcodeByFrame
543 return beamcodeByFrame
544
544
545
545
546 def __setDataByFrame(self):
546 def __setDataByFrame(self):
547 ndata = 2 # porque es complejo
547 ndata = 2 # porque es complejo
548 dataByFrame = numpy.zeros((self.radacHeaderObj.npulses, self.radacHeaderObj.nsamples, ndata))
548 dataByFrame = numpy.zeros((self.radacHeaderObj.npulses, self.radacHeaderObj.nsamples, ndata))
549 return dataByFrame
549 return dataByFrame
550
550
551 def __readDataSet(self):
551 def __readDataSet(self):
552 dataset = self.amisrFilePointer.get('Raw11/Data/Samples/Data')
552 dataset = self.amisrFilePointer.get('Raw11/Data/Samples/Data')
553 return dataset
553 return dataset
554
554
555 def __setDataBlock(self,):
555 def __setDataBlock(self,):
556 real = self.dataByFrame[:,:,0] #asumo que 0 es real
556 real = self.dataByFrame[:,:,0] #asumo que 0 es real
557 imag = self.dataByFrame[:,:,1] #asumo que 1 es imaginario
557 imag = self.dataByFrame[:,:,1] #asumo que 1 es imaginario
558 datablock = real + imag*1j #armo el complejo
558 datablock = real + imag*1j #armo el complejo
559 return datablock
559 return datablock
560
560
561 def readSamples_version1(self,idrecord):
561 def readSamples_version1(self,idrecord):
562 #estas tres primeras lineas solo se deben ejecutar una vez
562 #estas tres primeras lineas solo se deben ejecutar una vez
563 if self.flagIsNewFile:
563 if self.flagIsNewFile:
564 #reading dataset
564 #reading dataset
565 self.dataset = self.__readDataSet()
565 self.dataset = self.__readDataSet()
566 self.flagIsNewFile = 0
566 self.flagIsNewFile = 0
567
567
568 if idrecord == 0:
568 if idrecord == 0:
569 self.dataByFrame[self.index4_schain_datablock, : ,:] = self.dataset[0, self.index_amisr_sample,:,:]
569 self.dataByFrame[self.index4_schain_datablock, : ,:] = self.dataset[0, self.index_amisr_sample,:,:]
570 self.radacTimeByFrame[self.index4_schain_datablock] = self.radacHeaderObj.radacTime[0, self.index_amisr_sample]
570 self.radacTimeByFrame[self.index4_schain_datablock] = self.radacHeaderObj.radacTime[0, self.index_amisr_sample]
571 datablock = self.__setDataBlock()
571 datablock = self.__setDataBlock()
572 if len(self.index_amisr_buffer) > 0:
572 if len(self.index_amisr_buffer) > 0:
573 self.buffer = self.dataset[0, self.index_amisr_buffer,:,:]
573 self.buffer = self.dataset[0, self.index_amisr_buffer,:,:]
574 self.buffer_radactime = self.radacHeaderObj.radacTime[0, self.index_amisr_buffer]
574 self.buffer_radactime = self.radacHeaderObj.radacTime[0, self.index_amisr_buffer]
575
575
576 return datablock
576 return datablock
577 if len(self.index_amisr_buffer) > 0:
577 if len(self.index_amisr_buffer) > 0:
578 self.dataByFrame[self.index4_buffer,:,:] = self.buffer.copy()
578 self.dataByFrame[self.index4_buffer,:,:] = self.buffer.copy()
579 self.radacTimeByFrame[self.index4_buffer] = self.buffer_radactime.copy()
579 self.radacTimeByFrame[self.index4_buffer] = self.buffer_radactime.copy()
580 self.dataByFrame[self.index4_schain_datablock,:,:] = self.dataset[idrecord, self.index_amisr_sample,:,:]
580 self.dataByFrame[self.index4_schain_datablock,:,:] = self.dataset[idrecord, self.index_amisr_sample,:,:]
581 self.radacTimeByFrame[self.index4_schain_datablock] = self.radacHeaderObj.radacTime[idrecord, self.index_amisr_sample]
581 self.radacTimeByFrame[self.index4_schain_datablock] = self.radacHeaderObj.radacTime[idrecord, self.index_amisr_sample]
582 datablock = self.__setDataBlock()
582 datablock = self.__setDataBlock()
583 if len(self.index_amisr_buffer) > 0:
583 if len(self.index_amisr_buffer) > 0:
584 self.buffer = self.dataset[idrecord, self.index_amisr_buffer, :, :]
584 self.buffer = self.dataset[idrecord, self.index_amisr_buffer, :, :]
585 self.buffer_radactime = self.radacHeaderObj.radacTime[idrecord, self.index_amisr_buffer]
585 self.buffer_radactime = self.radacHeaderObj.radacTime[idrecord, self.index_amisr_buffer]
586
586
587 return datablock
587 return datablock
588
588
589
589
590 def readSamples(self,idrecord):
590 def readSamples(self,idrecord):
591 if self.flagIsNewFile:
591 if self.flagIsNewFile:
592 self.dataByFrame = self.__setDataByFrame()
592 self.dataByFrame = self.__setDataByFrame()
593 self.beamCodeByFrame = self.amisrFilePointer.get('Raw11/Data/RadacHeader/BeamCode').value[idrecord, :]
593 self.beamCodeByFrame = self.amisrFilePointer.get('Raw11/Data/RadacHeader/BeamCode').value[idrecord, :]
594
594
595 #reading ranges
595 #reading ranges
596 self.readRanges()
596 self.readRanges()
597 #reading dataset
597 #reading dataset
598 self.dataset = self.__readDataSet()
598 self.dataset = self.__readDataSet()
599
599
600 self.flagIsNewFile = 0
600 self.flagIsNewFile = 0
601 self.radacTimeByFrame = self.radacHeaderObj.radacTime.value[idrecord, :]
601 self.radacTimeByFrame = self.radacHeaderObj.radacTime.value[idrecord, :]
602 self.dataByFrame = self.dataset[idrecord, :, :, :]
602 self.dataByFrame = self.dataset[idrecord, :, :, :]
603 datablock = self.__setDataBlock()
603 datablock = self.__setDataBlock()
604 return datablock
604 return datablock
605
605
606
606
607 def readDataBlock(self):
607 def readDataBlock(self):
608
608
609 self.datablock = self.readSamples_version1(self.idrecord_count)
609 self.datablock = self.readSamples_version1(self.idrecord_count)
610 #self.datablock = self.readSamples(self.idrecord_count)
610 #self.datablock = self.readSamples(self.idrecord_count)
611 #print 'record:', self.idrecord_count
611 #print 'record:', self.idrecord_count
612
612
613 self.idrecord_count += 1
613 self.idrecord_count += 1
614 self.profileIndex = 0
614 self.profileIndex = 0
615
615
616 if self.idrecord_count >= self.radacHeaderObj.nrecords:
616 if self.idrecord_count >= self.radacHeaderObj.nrecords:
617 self.idrecord_count = 0
617 self.idrecord_count = 0
618 self.flagIsNewFile = 1
618 self.flagIsNewFile = 1
619
619
620 def readNextBlock(self):
620 def readNextBlock(self):
621
621
622 self.readDataBlock()
622 self.readDataBlock()
623
623
624 if self.flagIsNewFile:
624 if self.flagIsNewFile:
625 self.__setNextFile(self.online)
625 self.__setNextFile(self.online)
626 pass
626 pass
627
627
628 def __hasNotDataInBuffer(self):
628 def __hasNotDataInBuffer(self):
629 #self.radacHeaderObj.npulses debe ser otra variable para considerar el numero de pulsos a tomar en el primer y ultimo record
629 #self.radacHeaderObj.npulses debe ser otra variable para considerar el numero de pulsos a tomar en el primer y ultimo record
630 if self.profileIndex >= self.radacHeaderObj.npulses:
630 if self.profileIndex >= self.radacHeaderObj.npulses:
631 return 1
631 return 1
632 return 0
632 return 0
633
633
634 def printUTC(self):
634 def printUTC(self):
635 print self.dataOut.utctime
635 print(self.dataOut.utctime)
636 print ''
636 print('')
637
637
638 def setObjProperties(self):
638 def setObjProperties(self):
639
639
640 self.dataOut.heightList = self.rangeFromFile/1000.0 #km
640 self.dataOut.heightList = self.rangeFromFile/1000.0 #km
641 self.dataOut.nProfiles = self.radacHeaderObj.npulses
641 self.dataOut.nProfiles = self.radacHeaderObj.npulses
642 self.dataOut.nRecords = self.radacHeaderObj.nrecords
642 self.dataOut.nRecords = self.radacHeaderObj.nrecords
643 self.dataOut.nBeams = self.radacHeaderObj.nbeams
643 self.dataOut.nBeams = self.radacHeaderObj.nbeams
644 self.dataOut.ippSeconds = self.ippSeconds_fromfile
644 self.dataOut.ippSeconds = self.ippSeconds_fromfile
645 # self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt
645 # self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt
646 self.dataOut.frequency = self.frequency_h5file
646 self.dataOut.frequency = self.frequency_h5file
647 self.dataOut.npulseByFrame = self.npulseByFrame
647 self.dataOut.npulseByFrame = self.npulseByFrame
648 self.dataOut.nBaud = None
648 self.dataOut.nBaud = None
649 self.dataOut.nCode = None
649 self.dataOut.nCode = None
650 self.dataOut.code = None
650 self.dataOut.code = None
651
651
652 self.dataOut.beamCodeDict = self.beamCodeDict
652 self.dataOut.beamCodeDict = self.beamCodeDict
653 self.dataOut.beamRangeDict = self.beamRangeDict
653 self.dataOut.beamRangeDict = self.beamRangeDict
654
654
655 if self.timezone == 'lt':
655 if self.timezone == 'lt':
656 self.dataOut.timeZone = time.timezone / 60. #get the timezone in minutes
656 self.dataOut.timeZone = time.timezone / 60. #get the timezone in minutes
657 else:
657 else:
658 self.dataOut.timeZone = 0 #by default time is UTC
658 self.dataOut.timeZone = 0 #by default time is UTC
659
659
660 def getData(self):
660 def getData(self):
661
661
662 if self.flagNoMoreFiles:
662 if self.flagNoMoreFiles:
663 self.dataOut.flagNoData = True
663 self.dataOut.flagNoData = True
664 print 'Process finished'
664 print('Process finished')
665 return 0
665 return 0
666
666
667 if self.__hasNotDataInBuffer():
667 if self.__hasNotDataInBuffer():
668 self.readNextBlock()
668 self.readNextBlock()
669
669
670
670
671 if self.datablock is None: # setear esta condicion cuando no hayan datos por leers
671 if self.datablock is None: # setear esta condicion cuando no hayan datos por leers
672 self.dataOut.flagNoData = True
672 self.dataOut.flagNoData = True
673 return 0
673 return 0
674
674
675 self.dataOut.data = numpy.reshape(self.datablock[self.profileIndex,:],(1,-1))
675 self.dataOut.data = numpy.reshape(self.datablock[self.profileIndex,:],(1,-1))
676
676
677 self.dataOut.utctime = self.radacTimeByFrame[self.profileIndex]
677 self.dataOut.utctime = self.radacTimeByFrame[self.profileIndex]
678 self.dataOut.profileIndex = self.profileIndex
678 self.dataOut.profileIndex = self.profileIndex
679 self.dataOut.flagNoData = False
679 self.dataOut.flagNoData = False
680
680
681 self.profileIndex += 1
681 self.profileIndex += 1
682
682
683 return self.dataOut.data
683 return self.dataOut.data
684
684
685
685
686 def run(self, **kwargs):
686 def run(self, **kwargs):
687 if not(self.isConfig):
687 if not(self.isConfig):
688 self.setup(**kwargs)
688 self.setup(**kwargs)
689 self.setObjProperties()
689 self.setObjProperties()
690 self.isConfig = True
690 self.isConfig = True
691
691
692 self.getData()
692 self.getData() No newline at end of file
@@ -1,1826 +1,1826
1 '''
1 '''
2 Created on Jul 2, 2014
2 Created on Jul 2, 2014
3
3
4 @author: roj-idl71
4 @author: roj-idl71
5 '''
5 '''
6 import os
6 import os
7 import sys
7 import sys
8 import glob
8 import glob
9 import time
9 import time
10 import numpy
10 import numpy
11 import fnmatch
11 import fnmatch
12 import inspect
12 import inspect
13 import time
13 import time
14 import datetime
14 import datetime
15 import traceback
15 import traceback
16 import zmq
16 import zmq
17
17
18 try:
18 try:
19 from gevent import sleep
19 from gevent import sleep
20 except:
20 except:
21 from time import sleep
21 from time import sleep
22
22
23 import schainpy.admin
23 import schainpy.admin
24 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader
24 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader
25 from schainpy.model.data.jroheaderIO import get_dtype_index, get_numpy_dtype, get_procflag_dtype, get_dtype_width
25 from schainpy.model.data.jroheaderIO import get_dtype_index, get_numpy_dtype, get_procflag_dtype, get_dtype_width
26 from schainpy.utils import log
26 from schainpy.utils import log
27 import schainpy.admin
27 import schainpy.admin
28
28
29 LOCALTIME = True
29 LOCALTIME = True
30
30
31
31
32 def isNumber(cad):
32 def isNumber(cad):
33 """
33 """
34 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
34 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
35
35
36 Excepciones:
36 Excepciones:
37 Si un determinado string no puede ser convertido a numero
37 Si un determinado string no puede ser convertido a numero
38 Input:
38 Input:
39 str, string al cual se le analiza para determinar si convertible a un numero o no
39 str, string al cual se le analiza para determinar si convertible a un numero o no
40
40
41 Return:
41 Return:
42 True : si el string es uno numerico
42 True : si el string es uno numerico
43 False : no es un string numerico
43 False : no es un string numerico
44 """
44 """
45 try:
45 try:
46 float(cad)
46 float(cad)
47 return True
47 return True
48 except:
48 except:
49 return False
49 return False
50
50
51
51
52 def isFileInEpoch(filename, startUTSeconds, endUTSeconds):
52 def isFileInEpoch(filename, startUTSeconds, endUTSeconds):
53 """
53 """
54 Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado.
54 Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado.
55
55
56 Inputs:
56 Inputs:
57 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
57 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
58
58
59 startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en
59 startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en
60 segundos contados desde 01/01/1970.
60 segundos contados desde 01/01/1970.
61 endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en
61 endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en
62 segundos contados desde 01/01/1970.
62 segundos contados desde 01/01/1970.
63
63
64 Return:
64 Return:
65 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
65 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
66 fecha especificado, de lo contrario retorna False.
66 fecha especificado, de lo contrario retorna False.
67
67
68 Excepciones:
68 Excepciones:
69 Si el archivo no existe o no puede ser abierto
69 Si el archivo no existe o no puede ser abierto
70 Si la cabecera no puede ser leida.
70 Si la cabecera no puede ser leida.
71
71
72 """
72 """
73 basicHeaderObj = BasicHeader(LOCALTIME)
73 basicHeaderObj = BasicHeader(LOCALTIME)
74
74
75 try:
75 try:
76 fp = open(filename, 'rb')
76 fp = open(filename, 'rb')
77 except IOError:
77 except IOError:
78 print "The file %s can't be opened" % (filename)
78 print("The file %s can't be opened" % (filename))
79 return 0
79 return 0
80
80
81 sts = basicHeaderObj.read(fp)
81 sts = basicHeaderObj.read(fp)
82 fp.close()
82 fp.close()
83
83
84 if not(sts):
84 if not(sts):
85 print "Skipping the file %s because it has not a valid header" % (filename)
85 print("Skipping the file %s because it has not a valid header" % (filename))
86 return 0
86 return 0
87
87
88 if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)):
88 if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)):
89 return 0
89 return 0
90
90
91 return 1
91 return 1
92
92
93
93
94 def isTimeInRange(thisTime, startTime, endTime):
94 def isTimeInRange(thisTime, startTime, endTime):
95 if endTime >= startTime:
95 if endTime >= startTime:
96 if (thisTime < startTime) or (thisTime > endTime):
96 if (thisTime < startTime) or (thisTime > endTime):
97 return 0
97 return 0
98 return 1
98 return 1
99 else:
99 else:
100 if (thisTime < startTime) and (thisTime > endTime):
100 if (thisTime < startTime) and (thisTime > endTime):
101 return 0
101 return 0
102 return 1
102 return 1
103
103
104
104
105 def isFileInTimeRange(filename, startDate, endDate, startTime, endTime):
105 def isFileInTimeRange(filename, startDate, endDate, startTime, endTime):
106 """
106 """
107 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
107 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
108
108
109 Inputs:
109 Inputs:
110 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
110 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
111
111
112 startDate : fecha inicial del rango seleccionado en formato datetime.date
112 startDate : fecha inicial del rango seleccionado en formato datetime.date
113
113
114 endDate : fecha final del rango seleccionado en formato datetime.date
114 endDate : fecha final del rango seleccionado en formato datetime.date
115
115
116 startTime : tiempo inicial del rango seleccionado en formato datetime.time
116 startTime : tiempo inicial del rango seleccionado en formato datetime.time
117
117
118 endTime : tiempo final del rango seleccionado en formato datetime.time
118 endTime : tiempo final del rango seleccionado en formato datetime.time
119
119
120 Return:
120 Return:
121 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
121 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
122 fecha especificado, de lo contrario retorna False.
122 fecha especificado, de lo contrario retorna False.
123
123
124 Excepciones:
124 Excepciones:
125 Si el archivo no existe o no puede ser abierto
125 Si el archivo no existe o no puede ser abierto
126 Si la cabecera no puede ser leida.
126 Si la cabecera no puede ser leida.
127
127
128 """
128 """
129
129
130 try:
130 try:
131 fp = open(filename, 'rb')
131 fp = open(filename, 'rb')
132 except IOError:
132 except IOError:
133 print "The file %s can't be opened" % (filename)
133 print("The file %s can't be opened" % (filename))
134 return None
134 return None
135
135
136 firstBasicHeaderObj = BasicHeader(LOCALTIME)
136 firstBasicHeaderObj = BasicHeader(LOCALTIME)
137 systemHeaderObj = SystemHeader()
137 systemHeaderObj = SystemHeader()
138 radarControllerHeaderObj = RadarControllerHeader()
138 radarControllerHeaderObj = RadarControllerHeader()
139 processingHeaderObj = ProcessingHeader()
139 processingHeaderObj = ProcessingHeader()
140
140
141 lastBasicHeaderObj = BasicHeader(LOCALTIME)
141 lastBasicHeaderObj = BasicHeader(LOCALTIME)
142
142
143 sts = firstBasicHeaderObj.read(fp)
143 sts = firstBasicHeaderObj.read(fp)
144
144
145 if not(sts):
145 if not(sts):
146 print "[Reading] Skipping the file %s because it has not a valid header" % (filename)
146 print("[Reading] Skipping the file %s because it has not a valid header" % (filename))
147 return None
147 return None
148
148
149 if not systemHeaderObj.read(fp):
149 if not systemHeaderObj.read(fp):
150 return None
150 return None
151
151
152 if not radarControllerHeaderObj.read(fp):
152 if not radarControllerHeaderObj.read(fp):
153 return None
153 return None
154
154
155 if not processingHeaderObj.read(fp):
155 if not processingHeaderObj.read(fp):
156 return None
156 return None
157
157
158 filesize = os.path.getsize(filename)
158 filesize = os.path.getsize(filename)
159
159
160 offset = processingHeaderObj.blockSize + 24 # header size
160 offset = processingHeaderObj.blockSize + 24 # header size
161
161
162 if filesize <= offset:
162 if filesize <= offset:
163 print "[Reading] %s: This file has not enough data" % filename
163 print("[Reading] %s: This file has not enough data" % filename)
164 return None
164 return None
165
165
166 fp.seek(-offset, 2)
166 fp.seek(-offset, 2)
167
167
168 sts = lastBasicHeaderObj.read(fp)
168 sts = lastBasicHeaderObj.read(fp)
169
169
170 fp.close()
170 fp.close()
171
171
172 thisDatetime = lastBasicHeaderObj.datatime
172 thisDatetime = lastBasicHeaderObj.datatime
173 thisTime_last_block = thisDatetime.time()
173 thisTime_last_block = thisDatetime.time()
174
174
175 thisDatetime = firstBasicHeaderObj.datatime
175 thisDatetime = firstBasicHeaderObj.datatime
176 thisDate = thisDatetime.date()
176 thisDate = thisDatetime.date()
177 thisTime_first_block = thisDatetime.time()
177 thisTime_first_block = thisDatetime.time()
178
178
179 # General case
179 # General case
180 # o>>>>>>>>>>>>>><<<<<<<<<<<<<<o
180 # o>>>>>>>>>>>>>><<<<<<<<<<<<<<o
181 #-----------o----------------------------o-----------
181 #-----------o----------------------------o-----------
182 # startTime endTime
182 # startTime endTime
183
183
184 if endTime >= startTime:
184 if endTime >= startTime:
185 if (thisTime_last_block < startTime) or (thisTime_first_block > endTime):
185 if (thisTime_last_block < startTime) or (thisTime_first_block > endTime):
186 return None
186 return None
187
187
188 return thisDatetime
188 return thisDatetime
189
189
190 # If endTime < startTime then endTime belongs to the next day
190 # If endTime < startTime then endTime belongs to the next day
191
191
192 #<<<<<<<<<<<o o>>>>>>>>>>>
192 #<<<<<<<<<<<o o>>>>>>>>>>>
193 #-----------o----------------------------o-----------
193 #-----------o----------------------------o-----------
194 # endTime startTime
194 # endTime startTime
195
195
196 if (thisDate == startDate) and (thisTime_last_block < startTime):
196 if (thisDate == startDate) and (thisTime_last_block < startTime):
197 return None
197 return None
198
198
199 if (thisDate == endDate) and (thisTime_first_block > endTime):
199 if (thisDate == endDate) and (thisTime_first_block > endTime):
200 return None
200 return None
201
201
202 if (thisTime_last_block < startTime) and (thisTime_first_block > endTime):
202 if (thisTime_last_block < startTime) and (thisTime_first_block > endTime):
203 return None
203 return None
204
204
205 return thisDatetime
205 return thisDatetime
206
206
207
207
208 def isFolderInDateRange(folder, startDate=None, endDate=None):
208 def isFolderInDateRange(folder, startDate=None, endDate=None):
209 """
209 """
210 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
210 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
211
211
212 Inputs:
212 Inputs:
213 folder : nombre completo del directorio.
213 folder : nombre completo del directorio.
214 Su formato deberia ser "/path_root/?YYYYDDD"
214 Su formato deberia ser "/path_root/?YYYYDDD"
215
215
216 siendo:
216 siendo:
217 YYYY : Anio (ejemplo 2015)
217 YYYY : Anio (ejemplo 2015)
218 DDD : Dia del anio (ejemplo 305)
218 DDD : Dia del anio (ejemplo 305)
219
219
220 startDate : fecha inicial del rango seleccionado en formato datetime.date
220 startDate : fecha inicial del rango seleccionado en formato datetime.date
221
221
222 endDate : fecha final del rango seleccionado en formato datetime.date
222 endDate : fecha final del rango seleccionado en formato datetime.date
223
223
224 Return:
224 Return:
225 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
225 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
226 fecha especificado, de lo contrario retorna False.
226 fecha especificado, de lo contrario retorna False.
227 Excepciones:
227 Excepciones:
228 Si el directorio no tiene el formato adecuado
228 Si el directorio no tiene el formato adecuado
229 """
229 """
230
230
231 basename = os.path.basename(folder)
231 basename = os.path.basename(folder)
232
232
233 if not isRadarFolder(basename):
233 if not isRadarFolder(basename):
234 print "The folder %s has not the rigth format" % folder
234 print("The folder %s has not the rigth format" % folder)
235 return 0
235 return 0
236
236
237 if startDate and endDate:
237 if startDate and endDate:
238 thisDate = getDateFromRadarFolder(basename)
238 thisDate = getDateFromRadarFolder(basename)
239
239
240 if thisDate < startDate:
240 if thisDate < startDate:
241 return 0
241 return 0
242
242
243 if thisDate > endDate:
243 if thisDate > endDate:
244 return 0
244 return 0
245
245
246 return 1
246 return 1
247
247
248
248
249 def isFileInDateRange(filename, startDate=None, endDate=None):
249 def isFileInDateRange(filename, startDate=None, endDate=None):
250 """
250 """
251 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
251 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
252
252
253 Inputs:
253 Inputs:
254 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
254 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
255
255
256 Su formato deberia ser "?YYYYDDDsss"
256 Su formato deberia ser "?YYYYDDDsss"
257
257
258 siendo:
258 siendo:
259 YYYY : Anio (ejemplo 2015)
259 YYYY : Anio (ejemplo 2015)
260 DDD : Dia del anio (ejemplo 305)
260 DDD : Dia del anio (ejemplo 305)
261 sss : set
261 sss : set
262
262
263 startDate : fecha inicial del rango seleccionado en formato datetime.date
263 startDate : fecha inicial del rango seleccionado en formato datetime.date
264
264
265 endDate : fecha final del rango seleccionado en formato datetime.date
265 endDate : fecha final del rango seleccionado en formato datetime.date
266
266
267 Return:
267 Return:
268 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
268 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
269 fecha especificado, de lo contrario retorna False.
269 fecha especificado, de lo contrario retorna False.
270 Excepciones:
270 Excepciones:
271 Si el archivo no tiene el formato adecuado
271 Si el archivo no tiene el formato adecuado
272 """
272 """
273
273
274 basename = os.path.basename(filename)
274 basename = os.path.basename(filename)
275
275
276 if not isRadarFile(basename):
276 if not isRadarFile(basename):
277 print "The filename %s has not the rigth format" % filename
277 print("The filename %s has not the rigth format" % filename)
278 return 0
278 return 0
279
279
280 if startDate and endDate:
280 if startDate and endDate:
281 thisDate = getDateFromRadarFile(basename)
281 thisDate = getDateFromRadarFile(basename)
282
282
283 if thisDate < startDate:
283 if thisDate < startDate:
284 return 0
284 return 0
285
285
286 if thisDate > endDate:
286 if thisDate > endDate:
287 return 0
287 return 0
288
288
289 return 1
289 return 1
290
290
291
291
292 def getFileFromSet(path, ext, set):
292 def getFileFromSet(path, ext, set):
293 validFilelist = []
293 validFilelist = []
294 fileList = os.listdir(path)
294 fileList = os.listdir(path)
295
295
296 # 0 1234 567 89A BCDE
296 # 0 1234 567 89A BCDE
297 # H YYYY DDD SSS .ext
297 # H YYYY DDD SSS .ext
298
298
299 for thisFile in fileList:
299 for thisFile in fileList:
300 try:
300 try:
301 year = int(thisFile[1:5])
301 year = int(thisFile[1:5])
302 doy = int(thisFile[5:8])
302 doy = int(thisFile[5:8])
303 except:
303 except:
304 continue
304 continue
305
305
306 if (os.path.splitext(thisFile)[-1].lower() != ext.lower()):
306 if (os.path.splitext(thisFile)[-1].lower() != ext.lower()):
307 continue
307 continue
308
308
309 validFilelist.append(thisFile)
309 validFilelist.append(thisFile)
310
310
311 myfile = fnmatch.filter(
311 myfile = fnmatch.filter(
312 validFilelist, '*%4.4d%3.3d%3.3d*' % (year, doy, set))
312 validFilelist, '*%4.4d%3.3d%3.3d*' % (year, doy, set))
313
313
314 if len(myfile) != 0:
314 if len(myfile) != 0:
315 return myfile[0]
315 return myfile[0]
316 else:
316 else:
317 filename = '*%4.4d%3.3d%3.3d%s' % (year, doy, set, ext.lower())
317 filename = '*%4.4d%3.3d%3.3d%s' % (year, doy, set, ext.lower())
318 print 'the filename %s does not exist' % filename
318 print('the filename %s does not exist' % filename)
319 print '...going to the last file: '
319 print('...going to the last file: ')
320
320
321 if validFilelist:
321 if validFilelist:
322 validFilelist = sorted(validFilelist, key=str.lower)
322 validFilelist = sorted(validFilelist, key=str.lower)
323 return validFilelist[-1]
323 return validFilelist[-1]
324
324
325 return None
325 return None
326
326
327
327
328 def getlastFileFromPath(path, ext):
328 def getlastFileFromPath(path, ext):
329 """
329 """
330 Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext"
330 Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext"
331 al final de la depuracion devuelve el ultimo file de la lista que quedo.
331 al final de la depuracion devuelve el ultimo file de la lista que quedo.
332
332
333 Input:
333 Input:
334 fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta
334 fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta
335 ext : extension de los files contenidos en una carpeta
335 ext : extension de los files contenidos en una carpeta
336
336
337 Return:
337 Return:
338 El ultimo file de una determinada carpeta, no se considera el path.
338 El ultimo file de una determinada carpeta, no se considera el path.
339 """
339 """
340 validFilelist = []
340 validFilelist = []
341 fileList = os.listdir(path)
341 fileList = os.listdir(path)
342
342
343 # 0 1234 567 89A BCDE
343 # 0 1234 567 89A BCDE
344 # H YYYY DDD SSS .ext
344 # H YYYY DDD SSS .ext
345
345
346 for thisFile in fileList:
346 for thisFile in fileList:
347
347
348 year = thisFile[1:5]
348 year = thisFile[1:5]
349 if not isNumber(year):
349 if not isNumber(year):
350 continue
350 continue
351
351
352 doy = thisFile[5:8]
352 doy = thisFile[5:8]
353 if not isNumber(doy):
353 if not isNumber(doy):
354 continue
354 continue
355
355
356 year = int(year)
356 year = int(year)
357 doy = int(doy)
357 doy = int(doy)
358
358
359 if (os.path.splitext(thisFile)[-1].lower() != ext.lower()):
359 if (os.path.splitext(thisFile)[-1].lower() != ext.lower()):
360 continue
360 continue
361
361
362 validFilelist.append(thisFile)
362 validFilelist.append(thisFile)
363
363
364 if validFilelist:
364 if validFilelist:
365 validFilelist = sorted(validFilelist, key=str.lower)
365 validFilelist = sorted(validFilelist, key=str.lower)
366 return validFilelist[-1]
366 return validFilelist[-1]
367
367
368 return None
368 return None
369
369
370
370
371 def checkForRealPath(path, foldercounter, year, doy, set, ext):
371 def checkForRealPath(path, foldercounter, year, doy, set, ext):
372 """
372 """
373 Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path,
373 Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path,
374 Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar
374 Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar
375 el path exacto de un determinado file.
375 el path exacto de un determinado file.
376
376
377 Example :
377 Example :
378 nombre correcto del file es .../.../D2009307/P2009307367.ext
378 nombre correcto del file es .../.../D2009307/P2009307367.ext
379
379
380 Entonces la funcion prueba con las siguientes combinaciones
380 Entonces la funcion prueba con las siguientes combinaciones
381 .../.../y2009307367.ext
381 .../.../y2009307367.ext
382 .../.../Y2009307367.ext
382 .../.../Y2009307367.ext
383 .../.../x2009307/y2009307367.ext
383 .../.../x2009307/y2009307367.ext
384 .../.../x2009307/Y2009307367.ext
384 .../.../x2009307/Y2009307367.ext
385 .../.../X2009307/y2009307367.ext
385 .../.../X2009307/y2009307367.ext
386 .../.../X2009307/Y2009307367.ext
386 .../.../X2009307/Y2009307367.ext
387 siendo para este caso, la ultima combinacion de letras, identica al file buscado
387 siendo para este caso, la ultima combinacion de letras, identica al file buscado
388
388
389 Return:
389 Return:
390 Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file
390 Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file
391 caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas
391 caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas
392 para el filename
392 para el filename
393 """
393 """
394 fullfilename = None
394 fullfilename = None
395 find_flag = False
395 find_flag = False
396 filename = None
396 filename = None
397
397
398 prefixDirList = [None, 'd', 'D']
398 prefixDirList = [None, 'd', 'D']
399 if ext.lower() == ".r": # voltage
399 if ext.lower() == ".r": # voltage
400 prefixFileList = ['d', 'D']
400 prefixFileList = ['d', 'D']
401 elif ext.lower() == ".pdata": # spectra
401 elif ext.lower() == ".pdata": # spectra
402 prefixFileList = ['p', 'P']
402 prefixFileList = ['p', 'P']
403 else:
403 else:
404 return None, filename
404 return None, filename
405
405
406 # barrido por las combinaciones posibles
406 # barrido por las combinaciones posibles
407 for prefixDir in prefixDirList:
407 for prefixDir in prefixDirList:
408 thispath = path
408 thispath = path
409 if prefixDir != None:
409 if prefixDir != None:
410 # formo el nombre del directorio xYYYYDDD (x=d o x=D)
410 # formo el nombre del directorio xYYYYDDD (x=d o x=D)
411 if foldercounter == 0:
411 if foldercounter == 0:
412 thispath = os.path.join(path, "%s%04d%03d" %
412 thispath = os.path.join(path, "%s%04d%03d" %
413 (prefixDir, year, doy))
413 (prefixDir, year, doy))
414 else:
414 else:
415 thispath = os.path.join(path, "%s%04d%03d_%02d" % (
415 thispath = os.path.join(path, "%s%04d%03d_%02d" % (
416 prefixDir, year, doy, foldercounter))
416 prefixDir, year, doy, foldercounter))
417 for prefixFile in prefixFileList: # barrido por las dos combinaciones posibles de "D"
417 for prefixFile in prefixFileList: # barrido por las dos combinaciones posibles de "D"
418 # formo el nombre del file xYYYYDDDSSS.ext
418 # formo el nombre del file xYYYYDDDSSS.ext
419 filename = "%s%04d%03d%03d%s" % (prefixFile, year, doy, set, ext)
419 filename = "%s%04d%03d%03d%s" % (prefixFile, year, doy, set, ext)
420 fullfilename = os.path.join(
420 fullfilename = os.path.join(
421 thispath, filename) # formo el path completo
421 thispath, filename) # formo el path completo
422
422
423 if os.path.exists(fullfilename): # verifico que exista
423 if os.path.exists(fullfilename): # verifico que exista
424 find_flag = True
424 find_flag = True
425 break
425 break
426 if find_flag:
426 if find_flag:
427 break
427 break
428
428
429 if not(find_flag):
429 if not(find_flag):
430 return None, filename
430 return None, filename
431
431
432 return fullfilename, filename
432 return fullfilename, filename
433
433
434
434
435 def isRadarFolder(folder):
435 def isRadarFolder(folder):
436 try:
436 try:
437 year = int(folder[1:5])
437 year = int(folder[1:5])
438 doy = int(folder[5:8])
438 doy = int(folder[5:8])
439 except:
439 except:
440 return 0
440 return 0
441
441
442 return 1
442 return 1
443
443
444
444
445 def isRadarFile(file):
445 def isRadarFile(file):
446 try:
446 try:
447 year = int(file[1:5])
447 year = int(file[1:5])
448 doy = int(file[5:8])
448 doy = int(file[5:8])
449 set = int(file[8:11])
449 set = int(file[8:11])
450 except:
450 except:
451 return 0
451 return 0
452
452
453 return 1
453 return 1
454
454
455
455
456 def getDateFromRadarFile(file):
456 def getDateFromRadarFile(file):
457 try:
457 try:
458 year = int(file[1:5])
458 year = int(file[1:5])
459 doy = int(file[5:8])
459 doy = int(file[5:8])
460 set = int(file[8:11])
460 set = int(file[8:11])
461 except:
461 except:
462 return None
462 return None
463
463
464 thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy - 1)
464 thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy - 1)
465 return thisDate
465 return thisDate
466
466
467
467
468 def getDateFromRadarFolder(folder):
468 def getDateFromRadarFolder(folder):
469 try:
469 try:
470 year = int(folder[1:5])
470 year = int(folder[1:5])
471 doy = int(folder[5:8])
471 doy = int(folder[5:8])
472 except:
472 except:
473 return None
473 return None
474
474
475 thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy - 1)
475 thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy - 1)
476 return thisDate
476 return thisDate
477
477
478
478
479 class JRODataIO:
479 class JRODataIO:
480
480
481 c = 3E8
481 c = 3E8
482
482
483 isConfig = False
483 isConfig = False
484
484
485 basicHeaderObj = None
485 basicHeaderObj = None
486
486
487 systemHeaderObj = None
487 systemHeaderObj = None
488
488
489 radarControllerHeaderObj = None
489 radarControllerHeaderObj = None
490
490
491 processingHeaderObj = None
491 processingHeaderObj = None
492
492
493 dtype = None
493 dtype = None
494
494
495 pathList = []
495 pathList = []
496
496
497 filenameList = []
497 filenameList = []
498
498
499 filename = None
499 filename = None
500
500
501 ext = None
501 ext = None
502
502
503 flagIsNewFile = 1
503 flagIsNewFile = 1
504
504
505 flagDiscontinuousBlock = 0
505 flagDiscontinuousBlock = 0
506
506
507 flagIsNewBlock = 0
507 flagIsNewBlock = 0
508
508
509 fp = None
509 fp = None
510
510
511 firstHeaderSize = 0
511 firstHeaderSize = 0
512
512
513 basicHeaderSize = 24
513 basicHeaderSize = 24
514
514
515 versionFile = 1103
515 versionFile = 1103
516
516
517 fileSize = None
517 fileSize = None
518
518
519 # ippSeconds = None
519 # ippSeconds = None
520
520
521 fileSizeByHeader = None
521 fileSizeByHeader = None
522
522
523 fileIndex = None
523 fileIndex = None
524
524
525 profileIndex = None
525 profileIndex = None
526
526
527 blockIndex = None
527 blockIndex = None
528
528
529 nTotalBlocks = None
529 nTotalBlocks = None
530
530
531 maxTimeStep = 30
531 maxTimeStep = 30
532
532
533 lastUTTime = None
533 lastUTTime = None
534
534
535 datablock = None
535 datablock = None
536
536
537 dataOut = None
537 dataOut = None
538
538
539 blocksize = None
539 blocksize = None
540
540
541 getByBlock = False
541 getByBlock = False
542
542
543 def __init__(self):
543 def __init__(self):
544
544
545 raise NotImplementedError
545 raise NotImplementedError
546
546
547 def run(self):
547 def run(self):
548
548
549 raise NotImplementedError
549 raise NotImplementedError
550
550
551 def getDtypeWidth(self):
551 def getDtypeWidth(self):
552
552
553 dtype_index = get_dtype_index(self.dtype)
553 dtype_index = get_dtype_index(self.dtype)
554 dtype_width = get_dtype_width(dtype_index)
554 dtype_width = get_dtype_width(dtype_index)
555
555
556 return dtype_width
556 return dtype_width
557
557
558 def getAllowedArgs(self):
558 def getAllowedArgs(self):
559 if hasattr(self, '__attrs__'):
559 if hasattr(self, '__attrs__'):
560 return self.__attrs__
560 return self.__attrs__
561 else:
561 else:
562 return inspect.getargspec(self.run).args
562 return inspect.getargspec(self.run).args
563
563
564
564
565 class JRODataReader(JRODataIO):
565 class JRODataReader(JRODataIO):
566
566
567 online = 0
567 online = 0
568
568
569 realtime = 0
569 realtime = 0
570
570
571 nReadBlocks = 0
571 nReadBlocks = 0
572
572
573 delay = 10 # number of seconds waiting a new file
573 delay = 10 # number of seconds waiting a new file
574
574
575 nTries = 3 # quantity tries
575 nTries = 3 # quantity tries
576
576
577 nFiles = 3 # number of files for searching
577 nFiles = 3 # number of files for searching
578
578
579 path = None
579 path = None
580
580
581 foldercounter = 0
581 foldercounter = 0
582
582
583 flagNoMoreFiles = 0
583 flagNoMoreFiles = 0
584
584
585 datetimeList = []
585 datetimeList = []
586
586
587 __isFirstTimeOnline = 1
587 __isFirstTimeOnline = 1
588
588
589 __printInfo = True
589 __printInfo = True
590
590
591 profileIndex = None
591 profileIndex = None
592
592
593 nTxs = 1
593 nTxs = 1
594
594
595 txIndex = None
595 txIndex = None
596
596
597 # Added--------------------
597 # Added--------------------
598
598
599 selBlocksize = None
599 selBlocksize = None
600
600
601 selBlocktime = None
601 selBlocktime = None
602
602
603 def __init__(self):
603 def __init__(self):
604 """
604 """
605 This class is used to find data files
605 This class is used to find data files
606
606
607 Example:
607 Example:
608 reader = JRODataReader()
608 reader = JRODataReader()
609 fileList = reader.findDataFiles()
609 fileList = reader.findDataFiles()
610
610
611 """
611 """
612 pass
612 pass
613
613
614 def createObjByDefault(self):
614 def createObjByDefault(self):
615 """
615 """
616
616
617 """
617 """
618 raise NotImplementedError
618 raise NotImplementedError
619
619
620 def getBlockDimension(self):
620 def getBlockDimension(self):
621
621
622 raise NotImplementedError
622 raise NotImplementedError
623
623
624 def searchFilesOffLine(self,
624 def searchFilesOffLine(self,
625 path,
625 path,
626 startDate=None,
626 startDate=None,
627 endDate=None,
627 endDate=None,
628 startTime=datetime.time(0, 0, 0),
628 startTime=datetime.time(0, 0, 0),
629 endTime=datetime.time(23, 59, 59),
629 endTime=datetime.time(23, 59, 59),
630 set=None,
630 set=None,
631 expLabel='',
631 expLabel='',
632 ext='.r',
632 ext='.r',
633 cursor=None,
633 cursor=None,
634 skip=None,
634 skip=None,
635 walk=True):
635 walk=True):
636
636
637 self.filenameList = []
637 self.filenameList = []
638 self.datetimeList = []
638 self.datetimeList = []
639
639
640 pathList = []
640 pathList = []
641
641
642 dateList, pathList = self.findDatafiles(
642 dateList, pathList = self.findDatafiles(
643 path, startDate, endDate, expLabel, ext, walk, include_path=True)
643 path, startDate, endDate, expLabel, ext, walk, include_path=True)
644
644
645 if dateList == []:
645 if dateList == []:
646 return [], []
646 return [], []
647
647
648 if len(dateList) > 1:
648 if len(dateList) > 1:
649 print "[Reading] Data found for date range [%s - %s]: total days = %d" % (startDate, endDate, len(dateList))
649 print("[Reading] Data found for date range [%s - %s]: total days = %d" % (startDate, endDate, len(dateList)))
650 else:
650 else:
651 print "[Reading] Data found for date range [%s - %s]: date = %s" % (startDate, endDate, dateList[0])
651 print("[Reading] Data found for date range [%s - %s]: date = %s" % (startDate, endDate, dateList[0]))
652
652
653 filenameList = []
653 filenameList = []
654 datetimeList = []
654 datetimeList = []
655
655
656 for thisPath in pathList:
656 for thisPath in pathList:
657
657
658 fileList = glob.glob1(thisPath, "*%s" % ext)
658 fileList = glob.glob1(thisPath, "*%s" % ext)
659 fileList.sort()
659 fileList.sort()
660
660
661 for file in fileList:
661 for file in fileList:
662
662
663 filename = os.path.join(thisPath, file)
663 filename = os.path.join(thisPath, file)
664
664
665 if not isFileInDateRange(filename, startDate, endDate):
665 if not isFileInDateRange(filename, startDate, endDate):
666 continue
666 continue
667
667
668 thisDatetime = isFileInTimeRange(
668 thisDatetime = isFileInTimeRange(
669 filename, startDate, endDate, startTime, endTime)
669 filename, startDate, endDate, startTime, endTime)
670
670
671 if not(thisDatetime):
671 if not(thisDatetime):
672 continue
672 continue
673
673
674 filenameList.append(filename)
674 filenameList.append(filename)
675 datetimeList.append(thisDatetime)
675 datetimeList.append(thisDatetime)
676
676
677 if cursor is not None and skip is not None:
677 if cursor is not None and skip is not None:
678 filenameList = filenameList[cursor * skip:cursor * skip + skip]
678 filenameList = filenameList[cursor * skip:cursor * skip + skip]
679 datetimeList = datetimeList[cursor * skip:cursor * skip + skip]
679 datetimeList = datetimeList[cursor * skip:cursor * skip + skip]
680
680
681 if not(filenameList):
681 if not(filenameList):
682 print "[Reading] Time range selected invalid [%s - %s]: No *%s files in %s)" % (startTime, endTime, ext, path)
682 print("[Reading] Time range selected invalid [%s - %s]: No *%s files in %s)" % (startTime, endTime, ext, path))
683 return [], []
683 return [], []
684
684
685 print "[Reading] %d file(s) was(were) found in time range: %s - %s" % (len(filenameList), startTime, endTime)
685 print("[Reading] %d file(s) was(were) found in time range: %s - %s" % (len(filenameList), startTime, endTime))
686
686
687 # for i in range(len(filenameList)):
687 # for i in range(len(filenameList)):
688 # print "[Reading] %s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
688 # print "[Reading] %s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
689
689
690 self.filenameList = filenameList
690 self.filenameList = filenameList
691 self.datetimeList = datetimeList
691 self.datetimeList = datetimeList
692
692
693 return pathList, filenameList
693 return pathList, filenameList
694
694
695 def __searchFilesOnLine(self, path, expLabel="", ext=None, walk=True, set=None):
695 def __searchFilesOnLine(self, path, expLabel="", ext=None, walk=True, set=None):
696 """
696 """
697 Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y
697 Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y
698 devuelve el archivo encontrado ademas de otros datos.
698 devuelve el archivo encontrado ademas de otros datos.
699
699
700 Input:
700 Input:
701 path : carpeta donde estan contenidos los files que contiene data
701 path : carpeta donde estan contenidos los files que contiene data
702
702
703 expLabel : Nombre del subexperimento (subfolder)
703 expLabel : Nombre del subexperimento (subfolder)
704
704
705 ext : extension de los files
705 ext : extension de los files
706
706
707 walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath)
707 walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath)
708
708
709 Return:
709 Return:
710 directory : eL directorio donde esta el file encontrado
710 directory : eL directorio donde esta el file encontrado
711 filename : el ultimo file de una determinada carpeta
711 filename : el ultimo file de una determinada carpeta
712 year : el anho
712 year : el anho
713 doy : el numero de dia del anho
713 doy : el numero de dia del anho
714 set : el set del archivo
714 set : el set del archivo
715
715
716
716
717 """
717 """
718 if not os.path.isdir(path):
718 if not os.path.isdir(path):
719 return None, None, None, None, None, None
719 return None, None, None, None, None, None
720
720
721 dirList = []
721 dirList = []
722
722
723 if not walk:
723 if not walk:
724 fullpath = path
724 fullpath = path
725 foldercounter = 0
725 foldercounter = 0
726 else:
726 else:
727 # Filtra solo los directorios
727 # Filtra solo los directorios
728 for thisPath in os.listdir(path):
728 for thisPath in os.listdir(path):
729 if not os.path.isdir(os.path.join(path, thisPath)):
729 if not os.path.isdir(os.path.join(path, thisPath)):
730 continue
730 continue
731 if not isRadarFolder(thisPath):
731 if not isRadarFolder(thisPath):
732 continue
732 continue
733
733
734 dirList.append(thisPath)
734 dirList.append(thisPath)
735
735
736 if not(dirList):
736 if not(dirList):
737 return None, None, None, None, None, None
737 return None, None, None, None, None, None
738
738
739 dirList = sorted(dirList, key=str.lower)
739 dirList = sorted(dirList, key=str.lower)
740
740
741 doypath = dirList[-1]
741 doypath = dirList[-1]
742 foldercounter = int(doypath.split('_')[1]) if len(
742 foldercounter = int(doypath.split('_')[1]) if len(
743 doypath.split('_')) > 1 else 0
743 doypath.split('_')) > 1 else 0
744 fullpath = os.path.join(path, doypath, expLabel)
744 fullpath = os.path.join(path, doypath, expLabel)
745
745
746 print "[Reading] %s folder was found: " % (fullpath)
746 print("[Reading] %s folder was found: " % (fullpath))
747
747
748 if set == None:
748 if set == None:
749 filename = getlastFileFromPath(fullpath, ext)
749 filename = getlastFileFromPath(fullpath, ext)
750 else:
750 else:
751 filename = getFileFromSet(fullpath, ext, set)
751 filename = getFileFromSet(fullpath, ext, set)
752
752
753 if not(filename):
753 if not(filename):
754 return None, None, None, None, None, None
754 return None, None, None, None, None, None
755
755
756 print "[Reading] %s file was found" % (filename)
756 print("[Reading] %s file was found" % (filename))
757
757
758 if not(self.__verifyFile(os.path.join(fullpath, filename))):
758 if not(self.__verifyFile(os.path.join(fullpath, filename))):
759 return None, None, None, None, None, None
759 return None, None, None, None, None, None
760
760
761 year = int(filename[1:5])
761 year = int(filename[1:5])
762 doy = int(filename[5:8])
762 doy = int(filename[5:8])
763 set = int(filename[8:11])
763 set = int(filename[8:11])
764
764
765 return fullpath, foldercounter, filename, year, doy, set
765 return fullpath, foldercounter, filename, year, doy, set
766
766
767 def __setNextFileOffline(self):
767 def __setNextFileOffline(self):
768
768
769 idFile = self.fileIndex
769 idFile = self.fileIndex
770
770
771 while (True):
771 while (True):
772 idFile += 1
772 idFile += 1
773 if not(idFile < len(self.filenameList)):
773 if not(idFile < len(self.filenameList)):
774 self.flagNoMoreFiles = 1
774 self.flagNoMoreFiles = 1
775 # print "[Reading] No more Files"
775 # print "[Reading] No more Files"
776 return 0
776 return 0
777
777
778 filename = self.filenameList[idFile]
778 filename = self.filenameList[idFile]
779
779
780 if not(self.__verifyFile(filename)):
780 if not(self.__verifyFile(filename)):
781 continue
781 continue
782
782
783 fileSize = os.path.getsize(filename)
783 fileSize = os.path.getsize(filename)
784 fp = open(filename, 'rb')
784 fp = open(filename, 'rb')
785 break
785 break
786
786
787 self.flagIsNewFile = 1
787 self.flagIsNewFile = 1
788 self.fileIndex = idFile
788 self.fileIndex = idFile
789 self.filename = filename
789 self.filename = filename
790 self.fileSize = fileSize
790 self.fileSize = fileSize
791 self.fp = fp
791 self.fp = fp
792
792
793 # print "[Reading] Setting the file: %s"%self.filename
793 # print "[Reading] Setting the file: %s"%self.filename
794
794
795 return 1
795 return 1
796
796
797 def __setNextFileOnline(self):
797 def __setNextFileOnline(self):
798 """
798 """
799 Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si
799 Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si
800 no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files
800 no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files
801 siguientes.
801 siguientes.
802
802
803 Affected:
803 Affected:
804 self.flagIsNewFile
804 self.flagIsNewFile
805 self.filename
805 self.filename
806 self.fileSize
806 self.fileSize
807 self.fp
807 self.fp
808 self.set
808 self.set
809 self.flagNoMoreFiles
809 self.flagNoMoreFiles
810
810
811 Return:
811 Return:
812 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado
812 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado
813 1 : si el file fue abierto con exito y esta listo a ser leido
813 1 : si el file fue abierto con exito y esta listo a ser leido
814
814
815 Excepciones:
815 Excepciones:
816 Si un determinado file no puede ser abierto
816 Si un determinado file no puede ser abierto
817 """
817 """
818 nFiles = 0
818 nFiles = 0
819 fileOk_flag = False
819 fileOk_flag = False
820 firstTime_flag = True
820 firstTime_flag = True
821
821
822 self.set += 1
822 self.set += 1
823
823
824 if self.set > 999:
824 if self.set > 999:
825 self.set = 0
825 self.set = 0
826 self.foldercounter += 1
826 self.foldercounter += 1
827
827
828 # busca el 1er file disponible
828 # busca el 1er file disponible
829 fullfilename, filename = checkForRealPath(
829 fullfilename, filename = checkForRealPath(
830 self.path, self.foldercounter, self.year, self.doy, self.set, self.ext)
830 self.path, self.foldercounter, self.year, self.doy, self.set, self.ext)
831 if fullfilename:
831 if fullfilename:
832 if self.__verifyFile(fullfilename, False):
832 if self.__verifyFile(fullfilename, False):
833 fileOk_flag = True
833 fileOk_flag = True
834
834
835 # si no encuentra un file entonces espera y vuelve a buscar
835 # si no encuentra un file entonces espera y vuelve a buscar
836 if not(fileOk_flag):
836 if not(fileOk_flag):
837 # busco en los siguientes self.nFiles+1 files posibles
837 # busco en los siguientes self.nFiles+1 files posibles
838 for nFiles in range(self.nFiles + 1):
838 for nFiles in range(self.nFiles + 1):
839
839
840 if firstTime_flag: # si es la 1era vez entonces hace el for self.nTries veces
840 if firstTime_flag: # si es la 1era vez entonces hace el for self.nTries veces
841 tries = self.nTries
841 tries = self.nTries
842 else:
842 else:
843 tries = 1 # si no es la 1era vez entonces solo lo hace una vez
843 tries = 1 # si no es la 1era vez entonces solo lo hace una vez
844
844
845 for nTries in range(tries):
845 for nTries in range(tries):
846 if firstTime_flag:
846 if firstTime_flag:
847 print "\t[Reading] Waiting %0.2f sec for the next file: \"%s\" , try %03d ..." % (self.delay, filename, nTries + 1)
847 print("\t[Reading] Waiting %0.2f sec for the next file: \"%s\" , try %03d ..." % (self.delay, filename, nTries + 1))
848 sleep(self.delay)
848 sleep(self.delay)
849 else:
849 else:
850 print "\t[Reading] Searching the next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext)
850 print("\t[Reading] Searching the next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext))
851
851
852 fullfilename, filename = checkForRealPath(
852 fullfilename, filename = checkForRealPath(
853 self.path, self.foldercounter, self.year, self.doy, self.set, self.ext)
853 self.path, self.foldercounter, self.year, self.doy, self.set, self.ext)
854 if fullfilename:
854 if fullfilename:
855 if self.__verifyFile(fullfilename):
855 if self.__verifyFile(fullfilename):
856 fileOk_flag = True
856 fileOk_flag = True
857 break
857 break
858
858
859 if fileOk_flag:
859 if fileOk_flag:
860 break
860 break
861
861
862 firstTime_flag = False
862 firstTime_flag = False
863
863
864 log.warning('Skipping the file {} due to this file doesn\'t exist'.format(filename))
864 log.warning('Skipping the file {} due to this file doesn\'t exist'.format(filename))
865 self.set += 1
865 self.set += 1
866
866
867 # si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta
867 # si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta
868 if nFiles == (self.nFiles - 1):
868 if nFiles == (self.nFiles - 1):
869 self.set = 0
869 self.set = 0
870 self.doy += 1
870 self.doy += 1
871 self.foldercounter = 0
871 self.foldercounter = 0
872
872
873 if fileOk_flag:
873 if fileOk_flag:
874 self.fileSize = os.path.getsize(fullfilename)
874 self.fileSize = os.path.getsize(fullfilename)
875 self.filename = fullfilename
875 self.filename = fullfilename
876 self.flagIsNewFile = 1
876 self.flagIsNewFile = 1
877 if self.fp != None:
877 if self.fp != None:
878 self.fp.close()
878 self.fp.close()
879 self.fp = open(fullfilename, 'rb')
879 self.fp = open(fullfilename, 'rb')
880 self.flagNoMoreFiles = 0
880 self.flagNoMoreFiles = 0
881 # print '[Reading] Setting the file: %s' % fullfilename
881 # print '[Reading] Setting the file: %s' % fullfilename
882 else:
882 else:
883 self.fileSize = 0
883 self.fileSize = 0
884 self.filename = None
884 self.filename = None
885 self.flagIsNewFile = 0
885 self.flagIsNewFile = 0
886 self.fp = None
886 self.fp = None
887 self.flagNoMoreFiles = 1
887 self.flagNoMoreFiles = 1
888
888
889 return fileOk_flag
889 return fileOk_flag
890
890
891 def setNextFile(self):
891 def setNextFile(self):
892 if self.fp != None:
892 if self.fp != None:
893 self.fp.close()
893 self.fp.close()
894
894
895 if self.online:
895 if self.online:
896 newFile = self.__setNextFileOnline()
896 newFile = self.__setNextFileOnline()
897 else:
897 else:
898 newFile = self.__setNextFileOffline()
898 newFile = self.__setNextFileOffline()
899
899
900 if not(newFile):
900 if not(newFile):
901 raise schainpy.admin.SchainWarning('No more files to read')
901 raise schainpy.admin.SchainWarning('No more files to read')
902 return 0
902 return 0
903
903
904 if self.verbose:
904 if self.verbose:
905 print '[Reading] Setting the file: %s' % self.filename
905 print('[Reading] Setting the file: %s' % self.filename)
906
906
907 self.__readFirstHeader()
907 self.__readFirstHeader()
908 self.nReadBlocks = 0
908 self.nReadBlocks = 0
909 return 1
909 return 1
910
910
911 def __waitNewBlock(self):
911 def __waitNewBlock(self):
912 """
912 """
913 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
913 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
914
914
915 Si el modo de lectura es OffLine siempre retorn 0
915 Si el modo de lectura es OffLine siempre retorn 0
916 """
916 """
917 if not self.online:
917 if not self.online:
918 return 0
918 return 0
919
919
920 if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile):
920 if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile):
921 return 0
921 return 0
922
922
923 currentPointer = self.fp.tell()
923 currentPointer = self.fp.tell()
924
924
925 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
925 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
926
926
927 for nTries in range(self.nTries):
927 for nTries in range(self.nTries):
928
928
929 self.fp.close()
929 self.fp.close()
930 self.fp = open(self.filename, 'rb')
930 self.fp = open(self.filename, 'rb')
931 self.fp.seek(currentPointer)
931 self.fp.seek(currentPointer)
932
932
933 self.fileSize = os.path.getsize(self.filename)
933 self.fileSize = os.path.getsize(self.filename)
934 currentSize = self.fileSize - currentPointer
934 currentSize = self.fileSize - currentPointer
935
935
936 if (currentSize >= neededSize):
936 if (currentSize >= neededSize):
937 self.basicHeaderObj.read(self.fp)
937 self.basicHeaderObj.read(self.fp)
938 return 1
938 return 1
939
939
940 if self.fileSize == self.fileSizeByHeader:
940 if self.fileSize == self.fileSizeByHeader:
941 # self.flagEoF = True
941 # self.flagEoF = True
942 return 0
942 return 0
943
943
944 print "[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries + 1)
944 print("[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries + 1))
945 sleep(self.delay)
945 sleep(self.delay)
946
946
947 return 0
947 return 0
948
948
949 def waitDataBlock(self, pointer_location):
949 def waitDataBlock(self, pointer_location):
950
950
951 currentPointer = pointer_location
951 currentPointer = pointer_location
952
952
953 neededSize = self.processingHeaderObj.blockSize # + self.basicHeaderSize
953 neededSize = self.processingHeaderObj.blockSize # + self.basicHeaderSize
954
954
955 for nTries in range(self.nTries):
955 for nTries in range(self.nTries):
956 self.fp.close()
956 self.fp.close()
957 self.fp = open(self.filename, 'rb')
957 self.fp = open(self.filename, 'rb')
958 self.fp.seek(currentPointer)
958 self.fp.seek(currentPointer)
959
959
960 self.fileSize = os.path.getsize(self.filename)
960 self.fileSize = os.path.getsize(self.filename)
961 currentSize = self.fileSize - currentPointer
961 currentSize = self.fileSize - currentPointer
962
962
963 if (currentSize >= neededSize):
963 if (currentSize >= neededSize):
964 return 1
964 return 1
965
965
966 print "[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries + 1)
966 print("[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries + 1))
967 sleep(self.delay)
967 sleep(self.delay)
968
968
969 return 0
969 return 0
970
970
971 def __jumpToLastBlock(self):
971 def __jumpToLastBlock(self):
972
972
973 if not(self.__isFirstTimeOnline):
973 if not(self.__isFirstTimeOnline):
974 return
974 return
975
975
976 csize = self.fileSize - self.fp.tell()
976 csize = self.fileSize - self.fp.tell()
977 blocksize = self.processingHeaderObj.blockSize
977 blocksize = self.processingHeaderObj.blockSize
978
978
979 # salta el primer bloque de datos
979 # salta el primer bloque de datos
980 if csize > self.processingHeaderObj.blockSize:
980 if csize > self.processingHeaderObj.blockSize:
981 self.fp.seek(self.fp.tell() + blocksize)
981 self.fp.seek(self.fp.tell() + blocksize)
982 else:
982 else:
983 return
983 return
984
984
985 csize = self.fileSize - self.fp.tell()
985 csize = self.fileSize - self.fp.tell()
986 neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize
986 neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize
987 while True:
987 while True:
988
988
989 if self.fp.tell() < self.fileSize:
989 if self.fp.tell() < self.fileSize:
990 self.fp.seek(self.fp.tell() + neededsize)
990 self.fp.seek(self.fp.tell() + neededsize)
991 else:
991 else:
992 self.fp.seek(self.fp.tell() - neededsize)
992 self.fp.seek(self.fp.tell() - neededsize)
993 break
993 break
994
994
995 # csize = self.fileSize - self.fp.tell()
995 # csize = self.fileSize - self.fp.tell()
996 # neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize
996 # neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize
997 # factor = int(csize/neededsize)
997 # factor = int(csize/neededsize)
998 # if factor > 0:
998 # if factor > 0:
999 # self.fp.seek(self.fp.tell() + factor*neededsize)
999 # self.fp.seek(self.fp.tell() + factor*neededsize)
1000
1000
1001 self.flagIsNewFile = 0
1001 self.flagIsNewFile = 0
1002 self.__isFirstTimeOnline = 0
1002 self.__isFirstTimeOnline = 0
1003
1003
1004 def __setNewBlock(self):
1004 def __setNewBlock(self):
1005 # if self.server is None:
1005 # if self.server is None:
1006 if self.fp == None:
1006 if self.fp == None:
1007 return 0
1007 return 0
1008
1008
1009 # if self.online:
1009 # if self.online:
1010 # self.__jumpToLastBlock()
1010 # self.__jumpToLastBlock()
1011
1011
1012 if self.flagIsNewFile:
1012 if self.flagIsNewFile:
1013 self.lastUTTime = self.basicHeaderObj.utc
1013 self.lastUTTime = self.basicHeaderObj.utc
1014 return 1
1014 return 1
1015
1015
1016 if self.realtime:
1016 if self.realtime:
1017 self.flagDiscontinuousBlock = 1
1017 self.flagDiscontinuousBlock = 1
1018 if not(self.setNextFile()):
1018 if not(self.setNextFile()):
1019 return 0
1019 return 0
1020 else:
1020 else:
1021 return 1
1021 return 1
1022 # if self.server is None:
1022 # if self.server is None:
1023 currentSize = self.fileSize - self.fp.tell()
1023 currentSize = self.fileSize - self.fp.tell()
1024 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
1024 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
1025 if (currentSize >= neededSize):
1025 if (currentSize >= neededSize):
1026 self.basicHeaderObj.read(self.fp)
1026 self.basicHeaderObj.read(self.fp)
1027 self.lastUTTime = self.basicHeaderObj.utc
1027 self.lastUTTime = self.basicHeaderObj.utc
1028 return 1
1028 return 1
1029 # else:
1029 # else:
1030 # self.basicHeaderObj.read(self.zHeader)
1030 # self.basicHeaderObj.read(self.zHeader)
1031 # self.lastUTTime = self.basicHeaderObj.utc
1031 # self.lastUTTime = self.basicHeaderObj.utc
1032 # return 1
1032 # return 1
1033 if self.__waitNewBlock():
1033 if self.__waitNewBlock():
1034 self.lastUTTime = self.basicHeaderObj.utc
1034 self.lastUTTime = self.basicHeaderObj.utc
1035 return 1
1035 return 1
1036 # if self.server is None:
1036 # if self.server is None:
1037 if not(self.setNextFile()):
1037 if not(self.setNextFile()):
1038 return 0
1038 return 0
1039
1039
1040 deltaTime = self.basicHeaderObj.utc - self.lastUTTime
1040 deltaTime = self.basicHeaderObj.utc - self.lastUTTime
1041 self.lastUTTime = self.basicHeaderObj.utc
1041 self.lastUTTime = self.basicHeaderObj.utc
1042
1042
1043 self.flagDiscontinuousBlock = 0
1043 self.flagDiscontinuousBlock = 0
1044
1044
1045 if deltaTime > self.maxTimeStep:
1045 if deltaTime > self.maxTimeStep:
1046 self.flagDiscontinuousBlock = 1
1046 self.flagDiscontinuousBlock = 1
1047
1047
1048 return 1
1048 return 1
1049
1049
1050 def readNextBlock(self):
1050 def readNextBlock(self):
1051
1051
1052 # Skip block out of startTime and endTime
1052 # Skip block out of startTime and endTime
1053 while True:
1053 while True:
1054 if not(self.__setNewBlock()):
1054 if not(self.__setNewBlock()):
1055 raise(schainpy.admin.SchainWarning('No more files'))
1055 raise schainpy
1056 return 0
1056 return 0
1057
1057
1058 if not(self.readBlock()):
1058 if not(self.readBlock()):
1059 return 0
1059 return 0
1060
1060
1061 self.getBasicHeader()
1061 self.getBasicHeader()
1062 if (self.dataOut.datatime < datetime.datetime.combine(self.startDate, self.startTime)) or (self.dataOut.datatime > datetime.datetime.combine(self.endDate, self.endTime)):
1062 if (self.dataOut.datatime < datetime.datetime.combine(self.startDate, self.startTime)) or (self.dataOut.datatime > datetime.datetime.combine(self.endDate, self.endTime)):
1063 print "[Reading] Block No. %d/%d -> %s [Skipping]" % (self.nReadBlocks,
1063 print("[Reading] Block No. %d/%d -> %s [Skipping]" % (self.nReadBlocks,
1064 self.processingHeaderObj.dataBlocksPerFile,
1064 self.processingHeaderObj.dataBlocksPerFile,
1065 self.dataOut.datatime.ctime())
1065 self.dataOut.datatime.ctime()))
1066 continue
1066 continue
1067
1067
1068 break
1068 break
1069
1069
1070 if self.verbose:
1070 if self.verbose:
1071 print "[Reading] Block No. %d/%d -> %s" % (self.nReadBlocks,
1071 print("[Reading] Block No. %d/%d -> %s" % (self.nReadBlocks,
1072 self.processingHeaderObj.dataBlocksPerFile,
1072 self.processingHeaderObj.dataBlocksPerFile,
1073 self.dataOut.datatime.ctime())
1073 self.dataOut.datatime.ctime()))
1074 return 1
1074 return 1
1075
1075
1076 def __readFirstHeader(self):
1076 def __readFirstHeader(self):
1077
1077
1078 self.basicHeaderObj.read(self.fp)
1078 self.basicHeaderObj.read(self.fp)
1079 self.systemHeaderObj.read(self.fp)
1079 self.systemHeaderObj.read(self.fp)
1080 self.radarControllerHeaderObj.read(self.fp)
1080 self.radarControllerHeaderObj.read(self.fp)
1081 self.processingHeaderObj.read(self.fp)
1081 self.processingHeaderObj.read(self.fp)
1082
1082
1083 self.firstHeaderSize = self.basicHeaderObj.size
1083 self.firstHeaderSize = self.basicHeaderObj.size
1084
1084
1085 datatype = int(numpy.log2((self.processingHeaderObj.processFlags &
1085 datatype = int(numpy.log2((self.processingHeaderObj.processFlags &
1086 PROCFLAG.DATATYPE_MASK)) - numpy.log2(PROCFLAG.DATATYPE_CHAR))
1086 PROCFLAG.DATATYPE_MASK)) - numpy.log2(PROCFLAG.DATATYPE_CHAR))
1087 if datatype == 0:
1087 if datatype == 0:
1088 datatype_str = numpy.dtype([('real', '<i1'), ('imag', '<i1')])
1088 datatype_str = numpy.dtype([('real', '<i1'), ('imag', '<i1')])
1089 elif datatype == 1:
1089 elif datatype == 1:
1090 datatype_str = numpy.dtype([('real', '<i2'), ('imag', '<i2')])
1090 datatype_str = numpy.dtype([('real', '<i2'), ('imag', '<i2')])
1091 elif datatype == 2:
1091 elif datatype == 2:
1092 datatype_str = numpy.dtype([('real', '<i4'), ('imag', '<i4')])
1092 datatype_str = numpy.dtype([('real', '<i4'), ('imag', '<i4')])
1093 elif datatype == 3:
1093 elif datatype == 3:
1094 datatype_str = numpy.dtype([('real', '<i8'), ('imag', '<i8')])
1094 datatype_str = numpy.dtype([('real', '<i8'), ('imag', '<i8')])
1095 elif datatype == 4:
1095 elif datatype == 4:
1096 datatype_str = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
1096 datatype_str = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
1097 elif datatype == 5:
1097 elif datatype == 5:
1098 datatype_str = numpy.dtype([('real', '<f8'), ('imag', '<f8')])
1098 datatype_str = numpy.dtype([('real', '<f8'), ('imag', '<f8')])
1099 else:
1099 else:
1100 raise ValueError, 'Data type was not defined'
1100 raise ValueError('Data type was not defined')
1101
1101
1102 self.dtype = datatype_str
1102 self.dtype = datatype_str
1103 #self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c
1103 #self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c
1104 self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + \
1104 self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + \
1105 self.firstHeaderSize + self.basicHeaderSize * \
1105 self.firstHeaderSize + self.basicHeaderSize * \
1106 (self.processingHeaderObj.dataBlocksPerFile - 1)
1106 (self.processingHeaderObj.dataBlocksPerFile - 1)
1107 # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels)
1107 # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels)
1108 # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels)
1108 # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels)
1109 self.getBlockDimension()
1109 self.getBlockDimension()
1110
1110
1111 def __verifyFile(self, filename, msgFlag=True):
1111 def __verifyFile(self, filename, msgFlag=True):
1112
1112
1113 msg = None
1113 msg = None
1114
1114
1115 try:
1115 try:
1116 fp = open(filename, 'rb')
1116 fp = open(filename, 'rb')
1117 except IOError:
1117 except IOError:
1118
1118
1119 if msgFlag:
1119 if msgFlag:
1120 print "[Reading] File %s can't be opened" % (filename)
1120 print("[Reading] File %s can't be opened" % (filename))
1121
1121
1122 return False
1122 return False
1123
1123
1124 currentPosition = fp.tell()
1124 currentPosition = fp.tell()
1125 neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize
1125 neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize
1126
1126
1127 if neededSize == 0:
1127 if neededSize == 0:
1128 basicHeaderObj = BasicHeader(LOCALTIME)
1128 basicHeaderObj = BasicHeader(LOCALTIME)
1129 systemHeaderObj = SystemHeader()
1129 systemHeaderObj = SystemHeader()
1130 radarControllerHeaderObj = RadarControllerHeader()
1130 radarControllerHeaderObj = RadarControllerHeader()
1131 processingHeaderObj = ProcessingHeader()
1131 processingHeaderObj = ProcessingHeader()
1132
1132
1133 if not(basicHeaderObj.read(fp)):
1133 if not(basicHeaderObj.read(fp)):
1134 fp.close()
1134 fp.close()
1135 return False
1135 return False
1136
1136
1137 if not(systemHeaderObj.read(fp)):
1137 if not(systemHeaderObj.read(fp)):
1138 fp.close()
1138 fp.close()
1139 return False
1139 return False
1140
1140
1141 if not(radarControllerHeaderObj.read(fp)):
1141 if not(radarControllerHeaderObj.read(fp)):
1142 fp.close()
1142 fp.close()
1143 return False
1143 return False
1144
1144
1145 if not(processingHeaderObj.read(fp)):
1145 if not(processingHeaderObj.read(fp)):
1146 fp.close()
1146 fp.close()
1147 return False
1147 return False
1148
1148
1149 neededSize = processingHeaderObj.blockSize + basicHeaderObj.size
1149 neededSize = processingHeaderObj.blockSize + basicHeaderObj.size
1150 else:
1150 else:
1151 msg = "[Reading] Skipping the file %s due to it hasn't enough data" % filename
1151 msg = "[Reading] Skipping the file %s due to it hasn't enough data" % filename
1152
1152
1153 fp.close()
1153 fp.close()
1154
1154
1155 fileSize = os.path.getsize(filename)
1155 fileSize = os.path.getsize(filename)
1156 currentSize = fileSize - currentPosition
1156 currentSize = fileSize - currentPosition
1157
1157
1158 if currentSize < neededSize:
1158 if currentSize < neededSize:
1159 if msgFlag and (msg != None):
1159 if msgFlag and (msg != None):
1160 print msg
1160 print(msg)
1161 return False
1161 return False
1162
1162
1163 return True
1163 return True
1164
1164
1165 def findDatafiles(self, path, startDate=None, endDate=None, expLabel='', ext='.r', walk=True, include_path=False):
1165 def findDatafiles(self, path, startDate=None, endDate=None, expLabel='', ext='.r', walk=True, include_path=False):
1166
1166
1167 path_empty = True
1167 path_empty = True
1168
1168
1169 dateList = []
1169 dateList = []
1170 pathList = []
1170 pathList = []
1171
1171
1172 multi_path = path.split(',')
1172 multi_path = path.split(',')
1173
1173
1174 if not walk:
1174 if not walk:
1175
1175
1176 for single_path in multi_path:
1176 for single_path in multi_path:
1177
1177
1178 if not os.path.isdir(single_path):
1178 if not os.path.isdir(single_path):
1179 continue
1179 continue
1180
1180
1181 fileList = glob.glob1(single_path, "*" + ext)
1181 fileList = glob.glob1(single_path, "*" + ext)
1182
1182
1183 if not fileList:
1183 if not fileList:
1184 continue
1184 continue
1185
1185
1186 path_empty = False
1186 path_empty = False
1187
1187
1188 fileList.sort()
1188 fileList.sort()
1189
1189
1190 for thisFile in fileList:
1190 for thisFile in fileList:
1191
1191
1192 if not os.path.isfile(os.path.join(single_path, thisFile)):
1192 if not os.path.isfile(os.path.join(single_path, thisFile)):
1193 continue
1193 continue
1194
1194
1195 if not isRadarFile(thisFile):
1195 if not isRadarFile(thisFile):
1196 continue
1196 continue
1197
1197
1198 if not isFileInDateRange(thisFile, startDate, endDate):
1198 if not isFileInDateRange(thisFile, startDate, endDate):
1199 continue
1199 continue
1200
1200
1201 thisDate = getDateFromRadarFile(thisFile)
1201 thisDate = getDateFromRadarFile(thisFile)
1202
1202
1203 if thisDate in dateList:
1203 if thisDate in dateList:
1204 continue
1204 continue
1205
1205
1206 dateList.append(thisDate)
1206 dateList.append(thisDate)
1207 pathList.append(single_path)
1207 pathList.append(single_path)
1208
1208
1209 else:
1209 else:
1210 for single_path in multi_path:
1210 for single_path in multi_path:
1211
1211
1212 if not os.path.isdir(single_path):
1212 if not os.path.isdir(single_path):
1213 continue
1213 continue
1214
1214
1215 dirList = []
1215 dirList = []
1216
1216
1217 for thisPath in os.listdir(single_path):
1217 for thisPath in os.listdir(single_path):
1218
1218
1219 if not os.path.isdir(os.path.join(single_path, thisPath)):
1219 if not os.path.isdir(os.path.join(single_path, thisPath)):
1220 continue
1220 continue
1221
1221
1222 if not isRadarFolder(thisPath):
1222 if not isRadarFolder(thisPath):
1223 continue
1223 continue
1224
1224
1225 if not isFolderInDateRange(thisPath, startDate, endDate):
1225 if not isFolderInDateRange(thisPath, startDate, endDate):
1226 continue
1226 continue
1227
1227
1228 dirList.append(thisPath)
1228 dirList.append(thisPath)
1229
1229
1230 if not dirList:
1230 if not dirList:
1231 continue
1231 continue
1232
1232
1233 dirList.sort()
1233 dirList.sort()
1234
1234
1235 for thisDir in dirList:
1235 for thisDir in dirList:
1236
1236
1237 datapath = os.path.join(single_path, thisDir, expLabel)
1237 datapath = os.path.join(single_path, thisDir, expLabel)
1238 fileList = glob.glob1(datapath, "*" + ext)
1238 fileList = glob.glob1(datapath, "*" + ext)
1239
1239
1240 if not fileList:
1240 if not fileList:
1241 continue
1241 continue
1242
1242
1243 path_empty = False
1243 path_empty = False
1244
1244
1245 thisDate = getDateFromRadarFolder(thisDir)
1245 thisDate = getDateFromRadarFolder(thisDir)
1246
1246
1247 pathList.append(datapath)
1247 pathList.append(datapath)
1248 dateList.append(thisDate)
1248 dateList.append(thisDate)
1249
1249
1250 dateList.sort()
1250 dateList.sort()
1251
1251
1252 if walk:
1252 if walk:
1253 pattern_path = os.path.join(multi_path[0], "[dYYYYDDD]", expLabel)
1253 pattern_path = os.path.join(multi_path[0], "[dYYYYDDD]", expLabel)
1254 else:
1254 else:
1255 pattern_path = multi_path[0]
1255 pattern_path = multi_path[0]
1256
1256
1257 if path_empty:
1257 if path_empty:
1258 print "[Reading] No *%s files in %s for %s to %s" % (ext, pattern_path, startDate, endDate)
1258 print("[Reading] No *%s files in %s for %s to %s" % (ext, pattern_path, startDate, endDate))
1259 else:
1259 else:
1260 if not dateList:
1260 if not dateList:
1261 print "[Reading] Date range selected invalid [%s - %s]: No *%s files in %s)" % (startDate, endDate, ext, path)
1261 print("[Reading] Date range selected invalid [%s - %s]: No *%s files in %s)" % (startDate, endDate, ext, path))
1262
1262
1263 if include_path:
1263 if include_path:
1264 return dateList, pathList
1264 return dateList, pathList
1265
1265
1266 return dateList
1266 return dateList
1267
1267
1268 def setup(self,
1268 def setup(self,
1269 path=None,
1269 path=None,
1270 startDate=None,
1270 startDate=None,
1271 endDate=None,
1271 endDate=None,
1272 startTime=datetime.time(0, 0, 0),
1272 startTime=datetime.time(0, 0, 0),
1273 endTime=datetime.time(23, 59, 59),
1273 endTime=datetime.time(23, 59, 59),
1274 set=None,
1274 set=None,
1275 expLabel="",
1275 expLabel="",
1276 ext=None,
1276 ext=None,
1277 online=False,
1277 online=False,
1278 delay=60,
1278 delay=60,
1279 walk=True,
1279 walk=True,
1280 getblock=False,
1280 getblock=False,
1281 nTxs=1,
1281 nTxs=1,
1282 realtime=False,
1282 realtime=False,
1283 blocksize=None,
1283 blocksize=None,
1284 blocktime=None,
1284 blocktime=None,
1285 skip=None,
1285 skip=None,
1286 cursor=None,
1286 cursor=None,
1287 warnings=True,
1287 warnings=True,
1288 verbose=True,
1288 verbose=True,
1289 server=None,
1289 server=None,
1290 format=None,
1290 format=None,
1291 oneDDict=None,
1291 oneDDict=None,
1292 twoDDict=None,
1292 twoDDict=None,
1293 ind2DList=None):
1293 ind2DList=None):
1294 if server is not None:
1294 if server is not None:
1295 if 'tcp://' in server:
1295 if 'tcp://' in server:
1296 address = server
1296 address = server
1297 else:
1297 else:
1298 address = 'ipc:///tmp/%s' % server
1298 address = 'ipc:///tmp/%s' % server
1299 self.server = address
1299 self.server = address
1300 self.context = zmq.Context()
1300 self.context = zmq.Context()
1301 self.receiver = self.context.socket(zmq.PULL)
1301 self.receiver = self.context.socket(zmq.PULL)
1302 self.receiver.connect(self.server)
1302 self.receiver.connect(self.server)
1303 time.sleep(0.5)
1303 time.sleep(0.5)
1304 print '[Starting] ReceiverData from {}'.format(self.server)
1304 print('[Starting] ReceiverData from {}'.format(self.server))
1305 else:
1305 else:
1306 self.server = None
1306 self.server = None
1307 if path == None:
1307 if path == None:
1308 raise ValueError, "[Reading] The path is not valid"
1308 raise ValueError("[Reading] The path is not valid")
1309
1309
1310 if ext == None:
1310 if ext == None:
1311 ext = self.ext
1311 ext = self.ext
1312
1312
1313 if online:
1313 if online:
1314 print "[Reading] Searching files in online mode..."
1314 print("[Reading] Searching files in online mode...")
1315
1315
1316 for nTries in range(self.nTries):
1316 for nTries in range(self.nTries):
1317 fullpath, foldercounter, file, year, doy, set = self.__searchFilesOnLine(
1317 fullpath, foldercounter, file, year, doy, set = self.__searchFilesOnLine(
1318 path=path, expLabel=expLabel, ext=ext, walk=walk, set=set)
1318 path=path, expLabel=expLabel, ext=ext, walk=walk, set=set)
1319
1319
1320 if fullpath:
1320 if fullpath:
1321 break
1321 break
1322
1322
1323 print '[Reading] Waiting %0.2f sec for an valid file in %s: try %02d ...' % (delay, path, nTries + 1)
1323 print('[Reading] Waiting %0.2f sec for an valid file in %s: try %02d ...' % (delay, path, nTries + 1))
1324 sleep(delay)
1324 sleep(delay)
1325
1325
1326 if not(fullpath):
1326 if not(fullpath):
1327 raise schainpy.admin.SchainWarning('There isn\'t any valid file in {}'.format(path))
1327 raise schainpy.admin.SchainWarning('There isn\'t any valid file in {}'.format(path))
1328 return
1328 return
1329
1329
1330 self.year = year
1330 self.year = year
1331 self.doy = doy
1331 self.doy = doy
1332 self.set = set - 1
1332 self.set = set - 1
1333 self.path = path
1333 self.path = path
1334 self.foldercounter = foldercounter
1334 self.foldercounter = foldercounter
1335 last_set = None
1335 last_set = None
1336 else:
1336 else:
1337 print "[Reading] Searching files in offline mode ..."
1337 print("[Reading] Searching files in offline mode ...")
1338 pathList, filenameList = self.searchFilesOffLine(path, startDate=startDate, endDate=endDate,
1338 pathList, filenameList = self.searchFilesOffLine(path, startDate=startDate, endDate=endDate,
1339 startTime=startTime, endTime=endTime,
1339 startTime=startTime, endTime=endTime,
1340 set=set, expLabel=expLabel, ext=ext,
1340 set=set, expLabel=expLabel, ext=ext,
1341 walk=walk, cursor=cursor,
1341 walk=walk, cursor=cursor,
1342 skip=skip)
1342 skip=skip)
1343
1343
1344 if not(pathList):
1344 if not(pathList):
1345 self.fileIndex = -1
1345 self.fileIndex = -1
1346 self.pathList = []
1346 self.pathList = []
1347 self.filenameList = []
1347 self.filenameList = []
1348 return
1348 return
1349
1349
1350 self.fileIndex = -1
1350 self.fileIndex = -1
1351 self.pathList = pathList
1351 self.pathList = pathList
1352 self.filenameList = filenameList
1352 self.filenameList = filenameList
1353 file_name = os.path.basename(filenameList[-1])
1353 file_name = os.path.basename(filenameList[-1])
1354 basename, ext = os.path.splitext(file_name)
1354 basename, ext = os.path.splitext(file_name)
1355 last_set = int(basename[-3:])
1355 last_set = int(basename[-3:])
1356
1356
1357 self.online = online
1357 self.online = online
1358 self.realtime = realtime
1358 self.realtime = realtime
1359 self.delay = delay
1359 self.delay = delay
1360 ext = ext.lower()
1360 ext = ext.lower()
1361 self.ext = ext
1361 self.ext = ext
1362 self.getByBlock = getblock
1362 self.getByBlock = getblock
1363 self.nTxs = nTxs
1363 self.nTxs = nTxs
1364 self.startTime = startTime
1364 self.startTime = startTime
1365 self.endTime = endTime
1365 self.endTime = endTime
1366 self.endDate = endDate
1366 self.endDate = endDate
1367 self.startDate = startDate
1367 self.startDate = startDate
1368 # Added-----------------
1368 # Added-----------------
1369 self.selBlocksize = blocksize
1369 self.selBlocksize = blocksize
1370 self.selBlocktime = blocktime
1370 self.selBlocktime = blocktime
1371
1371
1372 # Verbose-----------
1372 # Verbose-----------
1373 self.verbose = verbose
1373 self.verbose = verbose
1374 self.warnings = warnings
1374 self.warnings = warnings
1375
1375
1376 if not(self.setNextFile()):
1376 if not(self.setNextFile()):
1377 if (startDate != None) and (endDate != None):
1377 if (startDate != None) and (endDate != None):
1378 print "[Reading] No files in range: %s - %s" % (datetime.datetime.combine(startDate, startTime).ctime(), datetime.datetime.combine(endDate, endTime).ctime())
1378 print("[Reading] No files in range: %s - %s" % (datetime.datetime.combine(startDate, startTime).ctime(), datetime.datetime.combine(endDate, endTime).ctime()))
1379 elif startDate != None:
1379 elif startDate != None:
1380 print "[Reading] No files in range: %s" % (datetime.datetime.combine(startDate, startTime).ctime())
1380 print("[Reading] No files in range: %s" % (datetime.datetime.combine(startDate, startTime).ctime()))
1381 else:
1381 else:
1382 print "[Reading] No files"
1382 print("[Reading] No files")
1383
1383
1384 self.fileIndex = -1
1384 self.fileIndex = -1
1385 self.pathList = []
1385 self.pathList = []
1386 self.filenameList = []
1386 self.filenameList = []
1387 return
1387 return
1388
1388
1389 # self.getBasicHeader()
1389 # self.getBasicHeader()
1390
1390
1391 if last_set != None:
1391 if last_set != None:
1392 self.dataOut.last_block = last_set * \
1392 self.dataOut.last_block = last_set * \
1393 self.processingHeaderObj.dataBlocksPerFile + self.basicHeaderObj.dataBlock
1393 self.processingHeaderObj.dataBlocksPerFile + self.basicHeaderObj.dataBlock
1394 return
1394 return
1395
1395
1396 def getBasicHeader(self):
1396 def getBasicHeader(self):
1397
1397
1398 self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond / \
1398 self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond / \
1399 1000. + self.profileIndex * self.radarControllerHeaderObj.ippSeconds
1399 1000. + self.profileIndex * self.radarControllerHeaderObj.ippSeconds
1400
1400
1401 self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock
1401 self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock
1402
1402
1403 self.dataOut.timeZone = self.basicHeaderObj.timeZone
1403 self.dataOut.timeZone = self.basicHeaderObj.timeZone
1404
1404
1405 self.dataOut.dstFlag = self.basicHeaderObj.dstFlag
1405 self.dataOut.dstFlag = self.basicHeaderObj.dstFlag
1406
1406
1407 self.dataOut.errorCount = self.basicHeaderObj.errorCount
1407 self.dataOut.errorCount = self.basicHeaderObj.errorCount
1408
1408
1409 self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime
1409 self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime
1410
1410
1411 self.dataOut.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs
1411 self.dataOut.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs
1412
1412
1413 # self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock*self.nTxs
1413 # self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock*self.nTxs
1414
1414
1415 def getFirstHeader(self):
1415 def getFirstHeader(self):
1416
1416
1417 raise NotImplementedError
1417 raise NotImplementedError
1418
1418
1419 def getData(self):
1419 def getData(self):
1420
1420
1421 raise NotImplementedError
1421 raise NotImplementedError
1422
1422
1423 def hasNotDataInBuffer(self):
1423 def hasNotDataInBuffer(self):
1424
1424
1425 raise NotImplementedError
1425 raise NotImplementedError
1426
1426
1427 def readBlock(self):
1427 def readBlock(self):
1428
1428
1429 raise NotImplementedError
1429 raise NotImplementedError
1430
1430
1431 def isEndProcess(self):
1431 def isEndProcess(self):
1432
1432
1433 return self.flagNoMoreFiles
1433 return self.flagNoMoreFiles
1434
1434
1435 def printReadBlocks(self):
1435 def printReadBlocks(self):
1436
1436
1437 print "[Reading] Number of read blocks per file %04d" % self.nReadBlocks
1437 print("[Reading] Number of read blocks per file %04d" % self.nReadBlocks)
1438
1438
1439 def printTotalBlocks(self):
1439 def printTotalBlocks(self):
1440
1440
1441 print "[Reading] Number of read blocks %04d" % self.nTotalBlocks
1441 print("[Reading] Number of read blocks %04d" % self.nTotalBlocks)
1442
1442
1443 def printNumberOfBlock(self):
1443 def printNumberOfBlock(self):
1444 'SPAM!'
1444 'SPAM!'
1445
1445
1446 # if self.flagIsNewBlock:
1446 # if self.flagIsNewBlock:
1447 # print "[Reading] Block No. %d/%d -> %s" %(self.nReadBlocks,
1447 # print "[Reading] Block No. %d/%d -> %s" %(self.nReadBlocks,
1448 # self.processingHeaderObj.dataBlocksPerFile,
1448 # self.processingHeaderObj.dataBlocksPerFile,
1449 # self.dataOut.datatime.ctime())
1449 # self.dataOut.datatime.ctime())
1450
1450
1451 def printInfo(self):
1451 def printInfo(self):
1452
1452
1453 if self.__printInfo == False:
1453 if self.__printInfo == False:
1454 return
1454 return
1455
1455
1456 self.basicHeaderObj.printInfo()
1456 self.basicHeaderObj.printInfo()
1457 self.systemHeaderObj.printInfo()
1457 self.systemHeaderObj.printInfo()
1458 self.radarControllerHeaderObj.printInfo()
1458 self.radarControllerHeaderObj.printInfo()
1459 self.processingHeaderObj.printInfo()
1459 self.processingHeaderObj.printInfo()
1460
1460
1461 self.__printInfo = False
1461 self.__printInfo = False
1462
1462
1463 def run(self,
1463 def run(self,
1464 path=None,
1464 path=None,
1465 startDate=None,
1465 startDate=None,
1466 endDate=None,
1466 endDate=None,
1467 startTime=datetime.time(0, 0, 0),
1467 startTime=datetime.time(0, 0, 0),
1468 endTime=datetime.time(23, 59, 59),
1468 endTime=datetime.time(23, 59, 59),
1469 set=None,
1469 set=None,
1470 expLabel="",
1470 expLabel="",
1471 ext=None,
1471 ext=None,
1472 online=False,
1472 online=False,
1473 delay=60,
1473 delay=60,
1474 walk=True,
1474 walk=True,
1475 getblock=False,
1475 getblock=False,
1476 nTxs=1,
1476 nTxs=1,
1477 realtime=False,
1477 realtime=False,
1478 blocksize=None,
1478 blocksize=None,
1479 blocktime=None,
1479 blocktime=None,
1480 skip=None,
1480 skip=None,
1481 cursor=None,
1481 cursor=None,
1482 warnings=True,
1482 warnings=True,
1483 server=None,
1483 server=None,
1484 verbose=True,
1484 verbose=True,
1485 format=None,
1485 format=None,
1486 oneDDict=None,
1486 oneDDict=None,
1487 twoDDict=None,
1487 twoDDict=None,
1488 ind2DList=None, **kwargs):
1488 ind2DList=None, **kwargs):
1489
1489
1490 if not(self.isConfig):
1490 if not(self.isConfig):
1491 self.setup(path=path,
1491 self.setup(path=path,
1492 startDate=startDate,
1492 startDate=startDate,
1493 endDate=endDate,
1493 endDate=endDate,
1494 startTime=startTime,
1494 startTime=startTime,
1495 endTime=endTime,
1495 endTime=endTime,
1496 set=set,
1496 set=set,
1497 expLabel=expLabel,
1497 expLabel=expLabel,
1498 ext=ext,
1498 ext=ext,
1499 online=online,
1499 online=online,
1500 delay=delay,
1500 delay=delay,
1501 walk=walk,
1501 walk=walk,
1502 getblock=getblock,
1502 getblock=getblock,
1503 nTxs=nTxs,
1503 nTxs=nTxs,
1504 realtime=realtime,
1504 realtime=realtime,
1505 blocksize=blocksize,
1505 blocksize=blocksize,
1506 blocktime=blocktime,
1506 blocktime=blocktime,
1507 skip=skip,
1507 skip=skip,
1508 cursor=cursor,
1508 cursor=cursor,
1509 warnings=warnings,
1509 warnings=warnings,
1510 server=server,
1510 server=server,
1511 verbose=verbose,
1511 verbose=verbose,
1512 format=format,
1512 format=format,
1513 oneDDict=oneDDict,
1513 oneDDict=oneDDict,
1514 twoDDict=twoDDict,
1514 twoDDict=twoDDict,
1515 ind2DList=ind2DList)
1515 ind2DList=ind2DList)
1516 self.isConfig = True
1516 self.isConfig = True
1517 if server is None:
1517 if server is None:
1518 self.getData()
1518 self.getData()
1519 else:
1519 else:
1520 self.getFromServer()
1520 self.getFromServer()
1521
1521
1522
1522
1523 class JRODataWriter(JRODataIO):
1523 class JRODataWriter(JRODataIO):
1524
1524
1525 """
1525 """
1526 Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura
1526 Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura
1527 de los datos siempre se realiza por bloques.
1527 de los datos siempre se realiza por bloques.
1528 """
1528 """
1529
1529
1530 blockIndex = 0
1530 blockIndex = 0
1531
1531
1532 path = None
1532 path = None
1533
1533
1534 setFile = None
1534 setFile = None
1535
1535
1536 profilesPerBlock = None
1536 profilesPerBlock = None
1537
1537
1538 blocksPerFile = None
1538 blocksPerFile = None
1539
1539
1540 nWriteBlocks = 0
1540 nWriteBlocks = 0
1541
1541
1542 fileDate = None
1542 fileDate = None
1543
1543
1544 def __init__(self, dataOut=None):
1544 def __init__(self, dataOut=None):
1545 raise NotImplementedError
1545 raise NotImplementedError
1546
1546
1547 def hasAllDataInBuffer(self):
1547 def hasAllDataInBuffer(self):
1548 raise NotImplementedError
1548 raise NotImplementedError
1549
1549
1550 def setBlockDimension(self):
1550 def setBlockDimension(self):
1551 raise NotImplementedError
1551 raise NotImplementedError
1552
1552
1553 def writeBlock(self):
1553 def writeBlock(self):
1554 raise NotImplementedError
1554 raise NotImplementedError
1555
1555
1556 def putData(self):
1556 def putData(self):
1557 raise NotImplementedError
1557 raise NotImplementedError
1558
1558
1559 def getProcessFlags(self):
1559 def getProcessFlags(self):
1560
1560
1561 processFlags = 0
1561 processFlags = 0
1562
1562
1563 dtype_index = get_dtype_index(self.dtype)
1563 dtype_index = get_dtype_index(self.dtype)
1564 procflag_dtype = get_procflag_dtype(dtype_index)
1564 procflag_dtype = get_procflag_dtype(dtype_index)
1565
1565
1566 processFlags += procflag_dtype
1566 processFlags += procflag_dtype
1567
1567
1568 if self.dataOut.flagDecodeData:
1568 if self.dataOut.flagDecodeData:
1569 processFlags += PROCFLAG.DECODE_DATA
1569 processFlags += PROCFLAG.DECODE_DATA
1570
1570
1571 if self.dataOut.flagDeflipData:
1571 if self.dataOut.flagDeflipData:
1572 processFlags += PROCFLAG.DEFLIP_DATA
1572 processFlags += PROCFLAG.DEFLIP_DATA
1573
1573
1574 if self.dataOut.code is not None:
1574 if self.dataOut.code is not None:
1575 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
1575 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
1576
1576
1577 if self.dataOut.nCohInt > 1:
1577 if self.dataOut.nCohInt > 1:
1578 processFlags += PROCFLAG.COHERENT_INTEGRATION
1578 processFlags += PROCFLAG.COHERENT_INTEGRATION
1579
1579
1580 if self.dataOut.type == "Spectra":
1580 if self.dataOut.type == "Spectra":
1581 if self.dataOut.nIncohInt > 1:
1581 if self.dataOut.nIncohInt > 1:
1582 processFlags += PROCFLAG.INCOHERENT_INTEGRATION
1582 processFlags += PROCFLAG.INCOHERENT_INTEGRATION
1583
1583
1584 if self.dataOut.data_dc is not None:
1584 if self.dataOut.data_dc is not None:
1585 processFlags += PROCFLAG.SAVE_CHANNELS_DC
1585 processFlags += PROCFLAG.SAVE_CHANNELS_DC
1586
1586
1587 if self.dataOut.flagShiftFFT:
1587 if self.dataOut.flagShiftFFT:
1588 processFlags += PROCFLAG.SHIFT_FFT_DATA
1588 processFlags += PROCFLAG.SHIFT_FFT_DATA
1589
1589
1590 return processFlags
1590 return processFlags
1591
1591
1592 def setBasicHeader(self):
1592 def setBasicHeader(self):
1593
1593
1594 self.basicHeaderObj.size = self.basicHeaderSize # bytes
1594 self.basicHeaderObj.size = self.basicHeaderSize # bytes
1595 self.basicHeaderObj.version = self.versionFile
1595 self.basicHeaderObj.version = self.versionFile
1596 self.basicHeaderObj.dataBlock = self.nTotalBlocks
1596 self.basicHeaderObj.dataBlock = self.nTotalBlocks
1597
1597
1598 utc = numpy.floor(self.dataOut.utctime)
1598 utc = numpy.floor(self.dataOut.utctime)
1599 milisecond = (self.dataOut.utctime - utc) * 1000.0
1599 milisecond = (self.dataOut.utctime - utc) * 1000.0
1600
1600
1601 self.basicHeaderObj.utc = utc
1601 self.basicHeaderObj.utc = utc
1602 self.basicHeaderObj.miliSecond = milisecond
1602 self.basicHeaderObj.miliSecond = milisecond
1603 self.basicHeaderObj.timeZone = self.dataOut.timeZone
1603 self.basicHeaderObj.timeZone = self.dataOut.timeZone
1604 self.basicHeaderObj.dstFlag = self.dataOut.dstFlag
1604 self.basicHeaderObj.dstFlag = self.dataOut.dstFlag
1605 self.basicHeaderObj.errorCount = self.dataOut.errorCount
1605 self.basicHeaderObj.errorCount = self.dataOut.errorCount
1606
1606
1607 def setFirstHeader(self):
1607 def setFirstHeader(self):
1608 """
1608 """
1609 Obtiene una copia del First Header
1609 Obtiene una copia del First Header
1610
1610
1611 Affected:
1611 Affected:
1612
1612
1613 self.basicHeaderObj
1613 self.basicHeaderObj
1614 self.systemHeaderObj
1614 self.systemHeaderObj
1615 self.radarControllerHeaderObj
1615 self.radarControllerHeaderObj
1616 self.processingHeaderObj self.
1616 self.processingHeaderObj self.
1617
1617
1618 Return:
1618 Return:
1619 None
1619 None
1620 """
1620 """
1621
1621
1622 raise NotImplementedError
1622 raise NotImplementedError
1623
1623
1624 def __writeFirstHeader(self):
1624 def __writeFirstHeader(self):
1625 """
1625 """
1626 Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader)
1626 Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader)
1627
1627
1628 Affected:
1628 Affected:
1629 __dataType
1629 __dataType
1630
1630
1631 Return:
1631 Return:
1632 None
1632 None
1633 """
1633 """
1634
1634
1635 # CALCULAR PARAMETROS
1635 # CALCULAR PARAMETROS
1636
1636
1637 sizeLongHeader = self.systemHeaderObj.size + \
1637 sizeLongHeader = self.systemHeaderObj.size + \
1638 self.radarControllerHeaderObj.size + self.processingHeaderObj.size
1638 self.radarControllerHeaderObj.size + self.processingHeaderObj.size
1639 self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader
1639 self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader
1640
1640
1641 self.basicHeaderObj.write(self.fp)
1641 self.basicHeaderObj.write(self.fp)
1642 self.systemHeaderObj.write(self.fp)
1642 self.systemHeaderObj.write(self.fp)
1643 self.radarControllerHeaderObj.write(self.fp)
1643 self.radarControllerHeaderObj.write(self.fp)
1644 self.processingHeaderObj.write(self.fp)
1644 self.processingHeaderObj.write(self.fp)
1645
1645
1646 def __setNewBlock(self):
1646 def __setNewBlock(self):
1647 """
1647 """
1648 Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header
1648 Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header
1649
1649
1650 Return:
1650 Return:
1651 0 : si no pudo escribir nada
1651 0 : si no pudo escribir nada
1652 1 : Si escribio el Basic el First Header
1652 1 : Si escribio el Basic el First Header
1653 """
1653 """
1654 if self.fp == None:
1654 if self.fp == None:
1655 self.setNextFile()
1655 self.setNextFile()
1656
1656
1657 if self.flagIsNewFile:
1657 if self.flagIsNewFile:
1658 return 1
1658 return 1
1659
1659
1660 if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile:
1660 if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile:
1661 self.basicHeaderObj.write(self.fp)
1661 self.basicHeaderObj.write(self.fp)
1662 return 1
1662 return 1
1663
1663
1664 if not(self.setNextFile()):
1664 if not(self.setNextFile()):
1665 return 0
1665 return 0
1666
1666
1667 return 1
1667 return 1
1668
1668
1669 def writeNextBlock(self):
1669 def writeNextBlock(self):
1670 """
1670 """
1671 Selecciona el bloque siguiente de datos y los escribe en un file
1671 Selecciona el bloque siguiente de datos y los escribe en un file
1672
1672
1673 Return:
1673 Return:
1674 0 : Si no hizo pudo escribir el bloque de datos
1674 0 : Si no hizo pudo escribir el bloque de datos
1675 1 : Si no pudo escribir el bloque de datos
1675 1 : Si no pudo escribir el bloque de datos
1676 """
1676 """
1677 if not(self.__setNewBlock()):
1677 if not(self.__setNewBlock()):
1678 return 0
1678 return 0
1679
1679
1680 self.writeBlock()
1680 self.writeBlock()
1681
1681
1682 print "[Writing] Block No. %d/%d" % (self.blockIndex,
1682 print("[Writing] Block No. %d/%d" % (self.blockIndex,
1683 self.processingHeaderObj.dataBlocksPerFile)
1683 self.processingHeaderObj.dataBlocksPerFile))
1684
1684
1685 return 1
1685 return 1
1686
1686
1687 def setNextFile(self):
1687 def setNextFile(self):
1688 """
1688 """
1689 Determina el siguiente file que sera escrito
1689 Determina el siguiente file que sera escrito
1690
1690
1691 Affected:
1691 Affected:
1692 self.filename
1692 self.filename
1693 self.subfolder
1693 self.subfolder
1694 self.fp
1694 self.fp
1695 self.setFile
1695 self.setFile
1696 self.flagIsNewFile
1696 self.flagIsNewFile
1697
1697
1698 Return:
1698 Return:
1699 0 : Si el archivo no puede ser escrito
1699 0 : Si el archivo no puede ser escrito
1700 1 : Si el archivo esta listo para ser escrito
1700 1 : Si el archivo esta listo para ser escrito
1701 """
1701 """
1702 ext = self.ext
1702 ext = self.ext
1703 path = self.path
1703 path = self.path
1704
1704
1705 if self.fp != None:
1705 if self.fp != None:
1706 self.fp.close()
1706 self.fp.close()
1707
1707
1708 timeTuple = time.localtime(self.dataOut.utctime)
1708 timeTuple = time.localtime(self.dataOut.utctime)
1709 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year, timeTuple.tm_yday)
1709 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year, timeTuple.tm_yday)
1710
1710
1711 fullpath = os.path.join(path, subfolder)
1711 fullpath = os.path.join(path, subfolder)
1712 setFile = self.setFile
1712 setFile = self.setFile
1713
1713
1714 if not(os.path.exists(fullpath)):
1714 if not(os.path.exists(fullpath)):
1715 os.mkdir(fullpath)
1715 os.mkdir(fullpath)
1716 setFile = -1 # inicializo mi contador de seteo
1716 setFile = -1 # inicializo mi contador de seteo
1717 else:
1717 else:
1718 filesList = os.listdir(fullpath)
1718 filesList = os.listdir(fullpath)
1719 if len(filesList) > 0:
1719 if len(filesList) > 0:
1720 filesList = sorted(filesList, key=str.lower)
1720 filesList = sorted(filesList, key=str.lower)
1721 filen = filesList[-1]
1721 filen = filesList[-1]
1722 # el filename debera tener el siguiente formato
1722 # el filename debera tener el siguiente formato
1723 # 0 1234 567 89A BCDE (hex)
1723 # 0 1234 567 89A BCDE (hex)
1724 # x YYYY DDD SSS .ext
1724 # x YYYY DDD SSS .ext
1725 if isNumber(filen[8:11]):
1725 if isNumber(filen[8:11]):
1726 # inicializo mi contador de seteo al seteo del ultimo file
1726 # inicializo mi contador de seteo al seteo del ultimo file
1727 setFile = int(filen[8:11])
1727 setFile = int(filen[8:11])
1728 else:
1728 else:
1729 setFile = -1
1729 setFile = -1
1730 else:
1730 else:
1731 setFile = -1 # inicializo mi contador de seteo
1731 setFile = -1 # inicializo mi contador de seteo
1732
1732
1733 setFile += 1
1733 setFile += 1
1734
1734
1735 # If this is a new day it resets some values
1735 # If this is a new day it resets some values
1736 if self.dataOut.datatime.date() > self.fileDate:
1736 if self.dataOut.datatime.date() > self.fileDate:
1737 setFile = 0
1737 setFile = 0
1738 self.nTotalBlocks = 0
1738 self.nTotalBlocks = 0
1739
1739
1740 filen = '{}{:04d}{:03d}{:03d}{}'.format(
1740 filen = '{}{:04d}{:03d}{:03d}{}'.format(
1741 self.optchar, timeTuple.tm_year, timeTuple.tm_yday, setFile, ext)
1741 self.optchar, timeTuple.tm_year, timeTuple.tm_yday, setFile, ext)
1742
1742
1743 filename = os.path.join(path, subfolder, filen)
1743 filename = os.path.join(path, subfolder, filen)
1744
1744
1745 fp = open(filename, 'wb')
1745 fp = open(filename, 'wb')
1746
1746
1747 self.blockIndex = 0
1747 self.blockIndex = 0
1748
1748
1749 # guardando atributos
1749 # guardando atributos
1750 self.filename = filename
1750 self.filename = filename
1751 self.subfolder = subfolder
1751 self.subfolder = subfolder
1752 self.fp = fp
1752 self.fp = fp
1753 self.setFile = setFile
1753 self.setFile = setFile
1754 self.flagIsNewFile = 1
1754 self.flagIsNewFile = 1
1755 self.fileDate = self.dataOut.datatime.date()
1755 self.fileDate = self.dataOut.datatime.date()
1756
1756
1757 self.setFirstHeader()
1757 self.setFirstHeader()
1758
1758
1759 print '[Writing] Opening file: %s' % self.filename
1759 print('[Writing] Opening file: %s' % self.filename)
1760
1760
1761 self.__writeFirstHeader()
1761 self.__writeFirstHeader()
1762
1762
1763 return 1
1763 return 1
1764
1764
1765 def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=64, set=None, ext=None, datatype=4):
1765 def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=64, set=None, ext=None, datatype=4):
1766 """
1766 """
1767 Setea el tipo de formato en la cual sera guardada la data y escribe el First Header
1767 Setea el tipo de formato en la cual sera guardada la data y escribe el First Header
1768
1768
1769 Inputs:
1769 Inputs:
1770 path : directory where data will be saved
1770 path : directory where data will be saved
1771 profilesPerBlock : number of profiles per block
1771 profilesPerBlock : number of profiles per block
1772 set : initial file set
1772 set : initial file set
1773 datatype : An integer number that defines data type:
1773 datatype : An integer number that defines data type:
1774 0 : int8 (1 byte)
1774 0 : int8 (1 byte)
1775 1 : int16 (2 bytes)
1775 1 : int16 (2 bytes)
1776 2 : int32 (4 bytes)
1776 2 : int32 (4 bytes)
1777 3 : int64 (8 bytes)
1777 3 : int64 (8 bytes)
1778 4 : float32 (4 bytes)
1778 4 : float32 (4 bytes)
1779 5 : double64 (8 bytes)
1779 5 : double64 (8 bytes)
1780
1780
1781 Return:
1781 Return:
1782 0 : Si no realizo un buen seteo
1782 0 : Si no realizo un buen seteo
1783 1 : Si realizo un buen seteo
1783 1 : Si realizo un buen seteo
1784 """
1784 """
1785
1785
1786 if ext == None:
1786 if ext == None:
1787 ext = self.ext
1787 ext = self.ext
1788
1788
1789 self.ext = ext.lower()
1789 self.ext = ext.lower()
1790
1790
1791 self.path = path
1791 self.path = path
1792
1792
1793 if set is None:
1793 if set is None:
1794 self.setFile = -1
1794 self.setFile = -1
1795 else:
1795 else:
1796 self.setFile = set - 1
1796 self.setFile = set - 1
1797
1797
1798 self.blocksPerFile = blocksPerFile
1798 self.blocksPerFile = blocksPerFile
1799
1799
1800 self.profilesPerBlock = profilesPerBlock
1800 self.profilesPerBlock = profilesPerBlock
1801
1801
1802 self.dataOut = dataOut
1802 self.dataOut = dataOut
1803 self.fileDate = self.dataOut.datatime.date()
1803 self.fileDate = self.dataOut.datatime.date()
1804 # By default
1804 # By default
1805 self.dtype = self.dataOut.dtype
1805 self.dtype = self.dataOut.dtype
1806
1806
1807 if datatype is not None:
1807 if datatype is not None:
1808 self.dtype = get_numpy_dtype(datatype)
1808 self.dtype = get_numpy_dtype(datatype)
1809
1809
1810 if not(self.setNextFile()):
1810 if not(self.setNextFile()):
1811 print "[Writing] There isn't a next file"
1811 print("[Writing] There isn't a next file")
1812 return 0
1812 return 0
1813
1813
1814 self.setBlockDimension()
1814 self.setBlockDimension()
1815
1815
1816 return 1
1816 return 1
1817
1817
1818 def run(self, dataOut, path, blocksPerFile, profilesPerBlock=64, set=None, ext=None, datatype=4, **kwargs):
1818 def run(self, dataOut, path, blocksPerFile, profilesPerBlock=64, set=None, ext=None, datatype=4, **kwargs):
1819
1819
1820 if not(self.isConfig):
1820 if not(self.isConfig):
1821
1821
1822 self.setup(dataOut, path, blocksPerFile, profilesPerBlock=profilesPerBlock,
1822 self.setup(dataOut, path, blocksPerFile, profilesPerBlock=profilesPerBlock,
1823 set=set, ext=ext, datatype=datatype, **kwargs)
1823 set=set, ext=ext, datatype=datatype, **kwargs)
1824 self.isConfig = True
1824 self.isConfig = True
1825
1825
1826 self.putData()
1826 self.putData() No newline at end of file
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
General Comments 0
You need to be logged in to leave comments. Login now