##// END OF EJS Templates
new utils package:jroutils, jroutils_ftp...
Daniel Valdez -
r488:7067527ccf8e
parent child
Show More
1 NO CONTENT: new file 100644
NO CONTENT: new file 100644
@@ -0,0 +1,1
1 from jroutils_ftp import * No newline at end of file
@@ -0,0 +1,348
1 '''
2 @author: Daniel Suarez
3 '''
4 import os
5 import glob
6 import ftplib
7 from model.proc.jroproc_base import ProcessingUnit, Operation
8
9 class FTP():
10 """
11 Ftp is a public class used to define custom File Transfer Protocol from "ftplib" python module
12
13 Non-standard Python modules used: None
14
15 Written by "Daniel Suarez":mailto:daniel.suarez@jro.igp.gob.pe Oct. 26, 2010
16 """
17
18 def __init__(self,server = None, username=None, password=None, remotefolder=None):
19 """
20 This method is used to setting parameters for FTP and establishing connection to remote server
21
22 Inputs:
23 server - remote server IP Address
24
25 username - remote server Username
26
27 password - remote server password
28
29 remotefolder - remote server current working directory
30
31 Return: void
32
33 Affects:
34 self.status - in Error Case or Connection Failed this parameter is set to 1 else 0
35
36 self.folderList - sub-folder list of remote folder
37
38 self.fileList - file list of remote folder
39
40
41 """
42
43 if ((server == None) and (username==None) and (password==None) and (remotefolder==None)):
44 server, username, password, remotefolder = self.parmsByDefault()
45
46 self.server = server
47 self.username = username
48 self.password = password
49 self.remotefolder = remotefolder
50 self.file = None
51 self.ftp = None
52 self.status = 0
53
54 try:
55 self.ftp = ftplib.FTP(self.server)
56 self.ftp.login(self.username,self.password)
57 self.ftp.cwd(self.remotefolder)
58 # print 'Connect to FTP Server: Successfully'
59
60 except ftplib.all_errors:
61 print 'Error FTP Service'
62 self.status = 1
63 return
64
65
66
67 self.dirList = []
68
69 try:
70 self.dirList = self.ftp.nlst()
71
72 except ftplib.error_perm, resp:
73 if str(resp) == "550 No files found":
74 print "no files in this directory"
75 self.status = 1
76 return
77
78 except ftplib.all_errors:
79 print 'Error Displaying Dir-Files'
80 self.status = 1
81 return
82
83 self.fileList = []
84 self.folderList = []
85 #only for test
86 for f in self.dirList:
87 name, ext = os.path.splitext(f)
88 if ext != '':
89 self.fileList.append(f)
90 # print 'filename: %s - size: %d'%(f,self.ftp.size(f))
91
92 def parmsByDefault(self):
93 server = 'jro-app.igp.gob.pe'
94 username = 'wmaster'
95 password = 'mst2010vhf'
96 remotefolder = '/home/wmaster/graficos'
97
98 return server, username, password, remotefolder
99
100
101 def mkd(self,dirname):
102 """
103 mkd is used to make directory in remote server
104
105 Input:
106 dirname - directory name
107
108 Return:
109 1 in error case else 0
110 """
111 try:
112 self.ftp.mkd(dirname)
113 except:
114 print 'Error creating remote folder:%s'%dirname
115 return 1
116
117 return 0
118
119
120 def delete(self,filename):
121 """
122 delete is used to delete file in current working directory of remote server
123
124 Input:
125 filename - filename to delete in remote folder
126
127 Return:
128 1 in error case else 0
129 """
130
131 try:
132 self.ftp.delete(filename)
133 except:
134 print 'Error deleting remote file:%s'%filename
135 return 1
136
137 return 0
138
139 def download(self,filename,localfolder):
140 """
141 download is used to downloading file from remote folder into local folder
142
143 Inputs:
144 filename - filename to donwload
145
146 localfolder - directory local to store filename
147
148 Returns:
149 self.status - 1 in error case else 0
150 """
151
152 self.status = 0
153
154
155 if not(filename in self.fileList):
156 print 'filename:%s not exists'%filename
157 self.status = 1
158 return self.status
159
160 newfilename = os.path.join(localfolder,filename)
161
162 self.file = open(newfilename, 'wb')
163
164 try:
165 print 'Download: ' + filename
166 self.ftp.retrbinary('RETR ' + filename, self.__handleDownload)
167 print 'Download Complete'
168 except ftplib.all_errors:
169 print 'Error Downloading ' + filename
170 self.status = 1
171 return self.status
172
173 self.file.close()
174
175 return self.status
176
177
178 def __handleDownload(self,block):
179 """
180 __handleDownload is used to handle writing file
181 """
182 self.file.write(block)
183
184
185 def upload(self,filename,remotefolder=None):
186 """
187 upload is used to uploading local file to remote directory
188
189 Inputs:
190 filename - full path name of local file to store in remote directory
191
192 remotefolder - remote directory
193
194 Returns:
195 self.status - 1 in error case else 0
196 """
197
198 if remotefolder == None:
199 remotefolder = self.remotefolder
200
201 self.status = 0
202
203 try:
204 self.ftp.cwd(remotefolder)
205
206 self.file = open(filename, 'rb')
207
208 (head, tail) = os.path.split(filename)
209
210 command = "STOR " + tail
211
212 print 'Uploading: ' + tail
213 self.ftp.storbinary(command, self.file)
214 print 'Upload Completed'
215
216 except ftplib.all_errors:
217 print 'Error Uploading ' + tail
218 self.status = 1
219 return self.status
220
221 self.file.close()
222
223 #back to initial directory in __init__()
224 self.ftp.cwd(self.remotefolder)
225
226 return self.status
227
228
229 def dir(self,remotefolder):
230 """
231 dir is used to change working directory of remote server and get folder and file list
232
233 Input:
234 remotefolder - current working directory
235
236 Affects:
237 self.fileList - file list of working directory
238
239 Return:
240 infoList - list with filenames and size of file in bytes
241
242 self.folderList - folder list
243 """
244
245 self.remotefolder = remotefolder
246 print 'Change to ' + self.remotefolder
247 try:
248 self.ftp.cwd(remotefolder)
249 except ftplib.all_errors:
250 print 'Error Change to ' + self.remotefolder
251 infoList = None
252 self.folderList = None
253 return infoList,self.folderList
254
255 self.dirList = []
256
257 try:
258 self.dirList = self.ftp.nlst()
259
260 except ftplib.error_perm, resp:
261 if str(resp) == "550 No files found":
262 print "no files in this directory"
263 infoList = None
264 self.folderList = None
265 return infoList,self.folderList
266 except ftplib.all_errors:
267 print 'Error Displaying Dir-Files'
268 infoList = None
269 self.folderList = None
270 return infoList,self.folderList
271
272 infoList = []
273 self.fileList = []
274 self.folderList = []
275 for f in self.dirList:
276 name,ext = os.path.splitext(f)
277 if ext != '':
278 self.fileList.append(f)
279 value = (f,self.ftp.size(f))
280 infoList.append(value)
281
282 if ext == '':
283 self.folderList.append(f)
284
285 return infoList,self.folderList
286
287
288 def close(self):
289 """
290 close is used to close and end FTP connection
291
292 Inputs: None
293
294 Return: void
295
296 """
297 self.ftp.close()
298
299 class SendByFTP(Operation):
300 def __init__(self):
301 self.status = 1
302
303 def error_print(self, ValueError):
304 print ValueError, 'Error FTP'
305 print "don't worry the program is running..."
306
307 def connect(self, server, username, password, remotefolder):
308 if not(self.status):
309 return
310 try:
311 self.ftpObj = FTP(server, username, password, remotefolder)
312 except:
313 self.error_print(ValueError)
314 self.status = 0
315
316 def put(self):
317 if not(self.status):
318 return
319
320 try:
321 for filename in self.filenameList:
322 self.ftpObj.upload(filename)
323 except:
324 self.error_print(ValueError)
325 self.status = 0
326
327 def close(self):
328 if not(self.status):
329 return
330
331 self.ftpObj.close()
332
333 def filterByExt(self, ext, localfolder):
334 fnameList = glob.glob1(localfolder,ext)
335 self.filenameList = [os.path.join(localfolder,x) for x in fnameList]
336
337 if len(self.filenameList) == 0:
338 self.status = 0
339
340 def run(self, dataOut, ext, localfolder, remotefolder, server, username, password):
341
342 self.filterByExt(ext, localfolder)
343
344 self.connect(server, username, password, remotefolder)
345
346 self.put()
347
348 self.close()
@@ -1,4 +1,5
1 from model.data.jrodata import *
1 from model.data.jrodata import *
2 from model.io.jrodataIO import *
2 from model.io.jrodataIO import *
3 from model.proc.jroprocessing import *
3 from model.proc.jroprocessing import *
4 from model.graphics.jroplot import *
4 from model.graphics.jroplot import *
5 from model.utils.jroutils import * No newline at end of file
@@ -1,604 +1,604
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 numpy
6 import numpy
7 import copy
7 import copy
8 import datetime
8 import datetime
9
9
10 BASIC_STRUCTURE = numpy.dtype([
10 BASIC_STRUCTURE = numpy.dtype([
11 ('nSize','<u4'),
11 ('nSize','<u4'),
12 ('nVersion','<u2'),
12 ('nVersion','<u2'),
13 ('nDataBlockId','<u4'),
13 ('nDataBlockId','<u4'),
14 ('nUtime','<u4'),
14 ('nUtime','<u4'),
15 ('nMilsec','<u2'),
15 ('nMilsec','<u2'),
16 ('nTimezone','<i2'),
16 ('nTimezone','<i2'),
17 ('nDstflag','<i2'),
17 ('nDstflag','<i2'),
18 ('nErrorCount','<u4')
18 ('nErrorCount','<u4')
19 ])
19 ])
20
20
21 SYSTEM_STRUCTURE = numpy.dtype([
21 SYSTEM_STRUCTURE = numpy.dtype([
22 ('nSize','<u4'),
22 ('nSize','<u4'),
23 ('nNumSamples','<u4'),
23 ('nNumSamples','<u4'),
24 ('nNumProfiles','<u4'),
24 ('nNumProfiles','<u4'),
25 ('nNumChannels','<u4'),
25 ('nNumChannels','<u4'),
26 ('nADCResolution','<u4'),
26 ('nADCResolution','<u4'),
27 ('nPCDIOBusWidth','<u4'),
27 ('nPCDIOBusWidth','<u4'),
28 ])
28 ])
29
29
30 RADAR_STRUCTURE = numpy.dtype([
30 RADAR_STRUCTURE = numpy.dtype([
31 ('nSize','<u4'),
31 ('nSize','<u4'),
32 ('nExpType','<u4'),
32 ('nExpType','<u4'),
33 ('nNTx','<u4'),
33 ('nNTx','<u4'),
34 ('fIpp','<f4'),
34 ('fIpp','<f4'),
35 ('fTxA','<f4'),
35 ('fTxA','<f4'),
36 ('fTxB','<f4'),
36 ('fTxB','<f4'),
37 ('nNumWindows','<u4'),
37 ('nNumWindows','<u4'),
38 ('nNumTaus','<u4'),
38 ('nNumTaus','<u4'),
39 ('nCodeType','<u4'),
39 ('nCodeType','<u4'),
40 ('nLine6Function','<u4'),
40 ('nLine6Function','<u4'),
41 ('nLine5Function','<u4'),
41 ('nLine5Function','<u4'),
42 ('fClock','<f4'),
42 ('fClock','<f4'),
43 ('nPrePulseBefore','<u4'),
43 ('nPrePulseBefore','<u4'),
44 ('nPrePulseAfter','<u4'),
44 ('nPrePulseAfter','<u4'),
45 ('sRangeIPP','<a20'),
45 ('sRangeIPP','<a20'),
46 ('sRangeTxA','<a20'),
46 ('sRangeTxA','<a20'),
47 ('sRangeTxB','<a20'),
47 ('sRangeTxB','<a20'),
48 ])
48 ])
49
49
50 SAMPLING_STRUCTURE = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
50 SAMPLING_STRUCTURE = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
51
51
52
52
53 PROCESSING_STRUCTURE = numpy.dtype([
53 PROCESSING_STRUCTURE = numpy.dtype([
54 ('nSize','<u4'),
54 ('nSize','<u4'),
55 ('nDataType','<u4'),
55 ('nDataType','<u4'),
56 ('nSizeOfDataBlock','<u4'),
56 ('nSizeOfDataBlock','<u4'),
57 ('nProfilesperBlock','<u4'),
57 ('nProfilesperBlock','<u4'),
58 ('nDataBlocksperFile','<u4'),
58 ('nDataBlocksperFile','<u4'),
59 ('nNumWindows','<u4'),
59 ('nNumWindows','<u4'),
60 ('nProcessFlags','<u4'),
60 ('nProcessFlags','<u4'),
61 ('nCoherentIntegrations','<u4'),
61 ('nCoherentIntegrations','<u4'),
62 ('nIncoherentIntegrations','<u4'),
62 ('nIncoherentIntegrations','<u4'),
63 ('nTotalSpectra','<u4')
63 ('nTotalSpectra','<u4')
64 ])
64 ])
65
65
66 class Header(object):
66 class Header(object):
67
67
68 def __init__(self):
68 def __init__(self):
69 raise
69 raise
70
70
71 def copy(self):
71 def copy(self):
72 return copy.deepcopy(self)
72 return copy.deepcopy(self)
73
73
74 def read(self):
74 def read(self):
75
75
76 raise ValueError
76 raise ValueError
77
77
78 def write(self):
78 def write(self):
79
79
80 raise ValueError
80 raise ValueError
81
81
82 def printInfo(self):
82 def printInfo(self):
83
83
84 print "#"*100
84 print "#"*100
85 print self.__class__.__name__.upper()
85 print self.__class__.__name__.upper()
86 print "#"*100
86 print "#"*100
87 for key in self.__dict__.keys():
87 for key in self.__dict__.keys():
88 print "%s = %s" %(key, self.__dict__[key])
88 print "%s = %s" %(key, self.__dict__[key])
89
89
90 class BasicHeader(Header):
90 class BasicHeader(Header):
91
91
92 size = None
92 size = None
93 version = None
93 version = None
94 dataBlock = None
94 dataBlock = None
95 utc = None
95 utc = None
96 ltc = None
96 ltc = None
97 miliSecond = None
97 miliSecond = None
98 timeZone = None
98 timeZone = None
99 dstFlag = None
99 dstFlag = None
100 errorCount = None
100 errorCount = None
101 datatime = None
101 datatime = None
102
102
103 __LOCALTIME = None
103 __LOCALTIME = None
104
104
105 def __init__(self, useLocalTime=True):
105 def __init__(self, useLocalTime=True):
106
106
107 self.size = 24
107 self.size = 24
108 self.version = 0
108 self.version = 0
109 self.dataBlock = 0
109 self.dataBlock = 0
110 self.utc = 0
110 self.utc = 0
111 self.miliSecond = 0
111 self.miliSecond = 0
112 self.timeZone = 0
112 self.timeZone = 0
113 self.dstFlag = 0
113 self.dstFlag = 0
114 self.errorCount = 0
114 self.errorCount = 0
115
115
116 self.useLocalTime = useLocalTime
116 self.useLocalTime = useLocalTime
117
117
118 def read(self, fp):
118 def read(self, fp):
119 try:
119 try:
120
120
121 header = numpy.fromfile(fp, BASIC_STRUCTURE,1)
121 header = numpy.fromfile(fp, BASIC_STRUCTURE,1)
122
122
123 self.size = int(header['nSize'][0])
123 self.size = int(header['nSize'][0])
124 self.version = int(header['nVersion'][0])
124 self.version = int(header['nVersion'][0])
125 self.dataBlock = int(header['nDataBlockId'][0])
125 self.dataBlock = int(header['nDataBlockId'][0])
126 self.utc = int(header['nUtime'][0])
126 self.utc = int(header['nUtime'][0])
127 self.miliSecond = int(header['nMilsec'][0])
127 self.miliSecond = int(header['nMilsec'][0])
128 self.timeZone = int(header['nTimezone'][0])
128 self.timeZone = int(header['nTimezone'][0])
129 self.dstFlag = int(header['nDstflag'][0])
129 self.dstFlag = int(header['nDstflag'][0])
130 self.errorCount = int(header['nErrorCount'][0])
130 self.errorCount = int(header['nErrorCount'][0])
131
131
132 except Exception, e:
132 except Exception, e:
133 print "BasicHeader: "
133 print "BasicHeader: "
134 print e
134 print e
135 return 0
135 return 0
136
136
137 return 1
137 return 1
138
138
139 def write(self, fp):
139 def write(self, fp):
140
140
141 headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount)
141 headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount)
142 header = numpy.array(headerTuple, BASIC_STRUCTURE)
142 header = numpy.array(headerTuple, BASIC_STRUCTURE)
143 header.tofile(fp)
143 header.tofile(fp)
144
144
145 return 1
145 return 1
146
146
147 def get_ltc(self):
147 def get_ltc(self):
148
148
149 return self.utc - self.timeZone*60
149 return self.utc - self.timeZone*60
150
150
151 def set_ltc(self, value):
151 def set_ltc(self, value):
152
152
153 self.utc = value + self.timeZone*60
153 self.utc = value + self.timeZone*60
154
154
155 def get_datatime(self):
155 def get_datatime(self):
156
156
157 return datetime.datetime.utcfromtimestamp(self.ltc)
157 return datetime.datetime.utcfromtimestamp(self.ltc)
158
158
159 ltc = property(get_ltc, set_ltc)
159 ltc = property(get_ltc, set_ltc)
160 datatime = property(get_datatime)
160 datatime = property(get_datatime)
161
161
162 class SystemHeader(Header):
162 class SystemHeader(Header):
163
163
164 size = None
164 size = None
165 nSamples = None
165 nSamples = None
166 nProfiles = None
166 nProfiles = None
167 nChannels = None
167 nChannels = None
168 adcResolution = None
168 adcResolution = None
169 pciDioBusWidth = None
169 pciDioBusWidth = None
170
170
171 def __init__(self):
171 def __init__(self):
172 self.size = 24
172 self.size = 24
173 self.nSamples = 0
173 self.nSamples = 0
174 self.nProfiles = 0
174 self.nProfiles = 0
175 self.nChannels = 0
175 self.nChannels = 0
176 self.adcResolution = 0
176 self.adcResolution = 0
177 self.pciDioBusWidth = 0
177 self.pciDioBusWidth = 0
178
178
179 def read(self, fp):
179 def read(self, fp):
180 try:
180 try:
181 header = numpy.fromfile(fp,SYSTEM_STRUCTURE,1)
181 header = numpy.fromfile(fp,SYSTEM_STRUCTURE,1)
182 self.size = header['nSize'][0]
182 self.size = header['nSize'][0]
183 self.nSamples = header['nNumSamples'][0]
183 self.nSamples = header['nNumSamples'][0]
184 self.nProfiles = header['nNumProfiles'][0]
184 self.nProfiles = header['nNumProfiles'][0]
185 self.nChannels = header['nNumChannels'][0]
185 self.nChannels = header['nNumChannels'][0]
186 self.adcResolution = header['nADCResolution'][0]
186 self.adcResolution = header['nADCResolution'][0]
187 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
187 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
188
188
189 except Exception, e:
189 except Exception, e:
190 print "SystemHeader: " + e
190 print "SystemHeader: " + e
191 return 0
191 return 0
192
192
193 return 1
193 return 1
194
194
195 def write(self, fp):
195 def write(self, fp):
196
196
197 headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth)
197 headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth)
198 header = numpy.array(headerTuple,SYSTEM_STRUCTURE)
198 header = numpy.array(headerTuple,SYSTEM_STRUCTURE)
199 header.tofile(fp)
199 header.tofile(fp)
200
200
201 return 1
201 return 1
202
202
203 class RadarControllerHeader(Header):
203 class RadarControllerHeader(Header):
204
204
205 size = None
205 size = None
206 expType = None
206 expType = None
207 nTx = None
207 nTx = None
208 ipp = None
208 ipp = None
209 txA = None
209 txA = None
210 txB = None
210 txB = None
211 nWindows = None
211 nWindows = None
212 numTaus = None
212 numTaus = None
213 codeType = None
213 codeType = None
214 line6Function = None
214 line6Function = None
215 line5Function = None
215 line5Function = None
216 fClock = None
216 fClock = None
217 prePulseBefore = None
217 prePulseBefore = None
218 prePulserAfter = None
218 prePulserAfter = None
219 rangeIpp = None
219 rangeIpp = None
220 rangeTxA = None
220 rangeTxA = None
221 rangeTxB = None
221 rangeTxB = None
222
222
223 __C = 3e8
223 __C = 3e8
224
224
225 def __init__(self):
225 def __init__(self):
226 self.size = 116
226 self.size = 116
227 self.expType = 0
227 self.expType = 0
228 self.nTx = 0
228 self.nTx = 0
229 self.ipp = 0
229 self.ipp = 0
230 self.txA = 0
230 self.txA = 0
231 self.txB = 0
231 self.txB = 0
232 self.nWindows = 0
232 self.nWindows = 0
233 self.numTaus = 0
233 self.numTaus = 0
234 self.codeType = 0
234 self.codeType = 0
235 self.line6Function = 0
235 self.line6Function = 0
236 self.line5Function = 0
236 self.line5Function = 0
237 self.fClock = 0
237 self.fClock = 0
238 self.prePulseBefore = 0
238 self.prePulseBefore = 0
239 self.prePulserAfter = 0
239 self.prePulserAfter = 0
240 self.rangeIpp = 0
240 self.rangeIpp = 0
241 self.rangeTxA = 0
241 self.rangeTxA = 0
242 self.rangeTxB = 0
242 self.rangeTxB = 0
243
243
244 self.samplingWindow = None
244 self.samplingWindow = None
245 self.nHeights = None
245 self.nHeights = None
246 self.firstHeight = None
246 self.firstHeight = None
247 self.deltaHeight = None
247 self.deltaHeight = None
248 self.samplesWin = None
248 self.samplesWin = None
249
249
250 self.nCode = None
250 self.nCode = None
251 self.nBaud = None
251 self.nBaud = None
252 self.code = None
252 self.code = None
253 self.flip1 = None
253 self.flip1 = None
254 self.flip2 = None
254 self.flip2 = None
255
255
256 # self.dynamic = numpy.array([],numpy.dtype('byte'))
256 # self.dynamic = numpy.array([],numpy.dtype('byte'))
257
257
258
258
259 def read(self, fp):
259 def read(self, fp):
260 try:
260 try:
261 startFp = fp.tell()
261 startFp = fp.tell()
262 header = numpy.fromfile(fp,RADAR_STRUCTURE,1)
262 header = numpy.fromfile(fp,RADAR_STRUCTURE,1)
263
263
264 self.size = int(header['nSize'][0])
264 self.size = int(header['nSize'][0])
265 self.expType = int(header['nExpType'][0])
265 self.expType = int(header['nExpType'][0])
266 self.nTx = int(header['nNTx'][0])
266 self.nTx = int(header['nNTx'][0])
267 self.ipp = float(header['fIpp'][0])
267 self.ipp = float(header['fIpp'][0])
268 self.txA = float(header['fTxA'][0])
268 self.txA = float(header['fTxA'][0])
269 self.txB = float(header['fTxB'][0])
269 self.txB = float(header['fTxB'][0])
270 self.nWindows = int(header['nNumWindows'][0])
270 self.nWindows = int(header['nNumWindows'][0])
271 self.numTaus = int(header['nNumTaus'][0])
271 self.numTaus = int(header['nNumTaus'][0])
272 self.codeType = int(header['nCodeType'][0])
272 self.codeType = int(header['nCodeType'][0])
273 self.line6Function = int(header['nLine6Function'][0])
273 self.line6Function = int(header['nLine6Function'][0])
274 self.line5Function = int(header['nLine5Function'][0])
274 self.line5Function = int(header['nLine5Function'][0])
275 self.fClock = float(header['fClock'][0])
275 self.fClock = float(header['fClock'][0])
276 self.prePulseBefore = int(header['nPrePulseBefore'][0])
276 self.prePulseBefore = int(header['nPrePulseBefore'][0])
277 self.prePulserAfter = int(header['nPrePulseAfter'][0])
277 self.prePulserAfter = int(header['nPrePulseAfter'][0])
278 self.rangeIpp = header['sRangeIPP'][0]
278 self.rangeIpp = header['sRangeIPP'][0]
279 self.rangeTxA = header['sRangeTxA'][0]
279 self.rangeTxA = header['sRangeTxA'][0]
280 self.rangeTxB = header['sRangeTxB'][0]
280 self.rangeTxB = header['sRangeTxB'][0]
281 # jump Dynamic Radar Controller Header
281 # jump Dynamic Radar Controller Header
282 # jumpFp = self.size - 116
282 # jumpFp = self.size - 116
283 # self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpFp)
283 # self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpFp)
284 #pointer backward to dynamic header and read
284 #pointer backward to dynamic header and read
285 # backFp = fp.tell() - jumpFp
285 # backFp = fp.tell() - jumpFp
286 # fp.seek(backFp)
286 # fp.seek(backFp)
287
287
288 self.samplingWindow = numpy.fromfile(fp,SAMPLING_STRUCTURE,self.nWindows)
288 self.samplingWindow = numpy.fromfile(fp,SAMPLING_STRUCTURE,self.nWindows)
289
289
290 self.nHeights = int(numpy.sum(self.samplingWindow['nsa']))
290 self.nHeights = int(numpy.sum(self.samplingWindow['nsa']))
291 self.firstHeight = self.samplingWindow['h0']
291 self.firstHeight = self.samplingWindow['h0']
292 self.deltaHeight = self.samplingWindow['dh']
292 self.deltaHeight = self.samplingWindow['dh']
293 self.samplesWin = self.samplingWindow['nsa']
293 self.samplesWin = self.samplingWindow['nsa']
294
294
295 self.Taus = numpy.fromfile(fp,'<f4',self.numTaus)
295 self.Taus = numpy.fromfile(fp,'<f4',self.numTaus)
296
296
297 if self.codeType != 0:
297 if self.codeType != 0:
298 self.nCode = int(numpy.fromfile(fp,'<u4',1))
298 self.nCode = int(numpy.fromfile(fp,'<u4',1))
299 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
299 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
300 self.code = numpy.empty([self.nCode,self.nBaud],dtype='u1')
300 self.code = numpy.empty([self.nCode,self.nBaud],dtype='u1')
301
301
302 for ic in range(self.nCode):
302 for ic in range(self.nCode):
303 temp = numpy.fromfile(fp,'u4',int(numpy.ceil(self.nBaud/32.)))
303 temp = numpy.fromfile(fp,'u4',int(numpy.ceil(self.nBaud/32.)))
304 for ib in range(self.nBaud-1,-1,-1):
304 for ib in range(self.nBaud-1,-1,-1):
305 self.code[ic,ib] = temp[ib/32]%2
305 self.code[ic,ib] = temp[ib/32]%2
306 temp[ib/32] = temp[ib/32]/2
306 temp[ib/32] = temp[ib/32]/2
307 self.code = 2.0*self.code - 1.0
307 self.code = 2.0*self.code - 1.0
308
308 self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4
309
309 if self.line5Function == RCfunction.FLIP:
310 if self.line5Function == RCfunction.FLIP:
310 self.flip1 = numpy.fromfile(fp,'<u4',1)
311 self.flip1 = numpy.fromfile(fp,'<u4',1)
311
312
312 if self.line6Function == RCfunction.FLIP:
313 if self.line6Function == RCfunction.FLIP:
313 self.flip2 = numpy.fromfile(fp,'<u4',1)
314 self.flip2 = numpy.fromfile(fp,'<u4',1)
314
315
315 endFp = self.size + startFp
316 endFp = self.size + startFp
316 # jumpFp = endFp - fp.tell()
317 jumpFp = endFp - fp.tell()
317 # if jumpFp > 0:
318 if jumpFp > 0:
318 #
319 fp.seek(jumpFp)
319 fp.seek(endFp)
320
320
321 except Exception, e:
321 except Exception, e:
322 print "RadarControllerHeader: " + e
322 print "RadarControllerHeader: " + e
323 return 0
323 return 0
324
324
325 return 1
325 return 1
326
326
327 def write(self, fp):
327 def write(self, fp):
328 headerTuple = (self.size,
328 headerTuple = (self.size,
329 self.expType,
329 self.expType,
330 self.nTx,
330 self.nTx,
331 self.ipp,
331 self.ipp,
332 self.txA,
332 self.txA,
333 self.txB,
333 self.txB,
334 self.nWindows,
334 self.nWindows,
335 self.numTaus,
335 self.numTaus,
336 self.codeType,
336 self.codeType,
337 self.line6Function,
337 self.line6Function,
338 self.line5Function,
338 self.line5Function,
339 self.fClock,
339 self.fClock,
340 self.prePulseBefore,
340 self.prePulseBefore,
341 self.prePulserAfter,
341 self.prePulserAfter,
342 self.rangeIpp,
342 self.rangeIpp,
343 self.rangeTxA,
343 self.rangeTxA,
344 self.rangeTxB)
344 self.rangeTxB)
345
345
346 header = numpy.array(headerTuple,RADAR_STRUCTURE)
346 header = numpy.array(headerTuple,RADAR_STRUCTURE)
347 header.tofile(fp)
347 header.tofile(fp)
348
348
349 #dynamic = self.dynamic
349 #dynamic = self.dynamic
350 #dynamic.tofile(fp)
350 #dynamic.tofile(fp)
351
351
352 samplingWindow = self.samplingWindow
352 samplingWindow = self.samplingWindow
353 samplingWindow.tofile(fp)
353 samplingWindow.tofile(fp)
354
354
355 if self.numTaus > 0:
355 if self.numTaus > 0:
356 self.Taus.tofile(fp)
356 self.Taus.tofile(fp)
357
357
358 nCode = numpy.array(self.nCode, '<u4')
358 nCode = numpy.array(self.nCode, '<u4')
359 nCode.tofile(fp)
359 nCode.tofile(fp)
360 nBaud = numpy.array(self.nBaud, '<u4')
360 nBaud = numpy.array(self.nBaud, '<u4')
361 nBaud.tofile(fp)
361 nBaud.tofile(fp)
362 code1 = (self.code + 1.0)/2.
362 code1 = (self.code + 1.0)/2.
363
363
364 for ic in range(self.nCode):
364 for ic in range(self.nCode):
365 tempx = numpy.zeros(numpy.ceil(self.nBaud/32.))
365 tempx = numpy.zeros(numpy.ceil(self.nBaud/32.))
366 start = 0
366 start = 0
367 end = 32
367 end = 32
368 for i in range(len(tempx)):
368 for i in range(len(tempx)):
369 code_selected = code1[ic,start:end]
369 code_selected = code1[ic,start:end]
370 for j in range(len(code_selected)-1,-1,-1):
370 for j in range(len(code_selected)-1,-1,-1):
371 if code_selected[j] == 1:
371 if code_selected[j] == 1:
372 tempx[i] = tempx[i] + 2**(len(code_selected)-1-j)
372 tempx[i] = tempx[i] + 2**(len(code_selected)-1-j)
373 start = start + 32
373 start = start + 32
374 end = end + 32
374 end = end + 32
375
375
376 tempx = tempx.astype('u4')
376 tempx = tempx.astype('u4')
377 tempx.tofile(fp)
377 tempx.tofile(fp)
378
378
379 if self.line5Function == RCfunction.FLIP:
379 if self.line5Function == RCfunction.FLIP:
380 self.flip1.tofile(fp)
380 self.flip1.tofile(fp)
381
381
382 if self.line6Function == RCfunction.FLIP:
382 if self.line6Function == RCfunction.FLIP:
383 self.flip2.tofile(fp)
383 self.flip2.tofile(fp)
384
384
385 return 1
385 return 1
386
386
387 def get_ippSeconds(self):
387 def get_ippSeconds(self):
388 '''
388 '''
389 '''
389 '''
390 ippSeconds = 2.0 * 1000 * self.ipp / self.__C
390 ippSeconds = 2.0 * 1000 * self.ipp / self.__C
391
391
392 return ippSeconds
392 return ippSeconds
393
393
394 def set_ippSeconds(self, ippSeconds):
394 def set_ippSeconds(self, ippSeconds):
395 '''
395 '''
396 '''
396 '''
397
397
398 self.ipp = ippSeconds * self.__C / (2.0*1000)
398 self.ipp = ippSeconds * self.__C / (2.0*1000)
399
399
400 return
400 return
401
401
402 ippSeconds = property(get_ippSeconds, set_ippSeconds)
402 ippSeconds = property(get_ippSeconds, set_ippSeconds)
403
403
404 class ProcessingHeader(Header):
404 class ProcessingHeader(Header):
405
405
406 size = None
406 size = None
407 dtype = None
407 dtype = None
408 blockSize = None
408 blockSize = None
409 profilesPerBlock = None
409 profilesPerBlock = None
410 dataBlocksPerFile = None
410 dataBlocksPerFile = None
411 nWindows = None
411 nWindows = None
412 processFlags = None
412 processFlags = None
413 nCohInt = None
413 nCohInt = None
414 nIncohInt = None
414 nIncohInt = None
415 totalSpectra = None
415 totalSpectra = None
416
416
417 flag_dc = None
417 flag_dc = None
418 flag_cspc = None
418 flag_cspc = None
419
419
420 def __init__(self):
420 def __init__(self):
421 self.size = 0
421 self.size = 0
422 self.dtype = 0
422 self.dtype = 0
423 self.blockSize = 0
423 self.blockSize = 0
424 self.profilesPerBlock = 0
424 self.profilesPerBlock = 0
425 self.dataBlocksPerFile = 0
425 self.dataBlocksPerFile = 0
426 self.nWindows = 0
426 self.nWindows = 0
427 self.processFlags = 0
427 self.processFlags = 0
428 self.nCohInt = 0
428 self.nCohInt = 0
429 self.nIncohInt = 0
429 self.nIncohInt = 0
430 self.totalSpectra = 0
430 self.totalSpectra = 0
431
431
432 self.samplingWindow = 0
432 self.samplingWindow = 0
433
433
434 self.nHeights = 0
434 self.nHeights = 0
435 self.firstHeight = 0
435 self.firstHeight = 0
436 self.deltaHeight = 0
436 self.deltaHeight = 0
437 self.samplesWin = 0
437 self.samplesWin = 0
438 self.spectraComb = 0
438 self.spectraComb = 0
439 # self.nCode = None
439 # self.nCode = None
440 # self.code = None
440 # self.code = None
441 # self.nBaud = None
441 # self.nBaud = None
442 self.shif_fft = False
442 self.shif_fft = False
443 self.flag_dc = False
443 self.flag_dc = False
444 self.flag_cspc = False
444 self.flag_cspc = False
445
445
446 def read(self, fp):
446 def read(self, fp):
447 # try:
447 # try:
448 header = numpy.fromfile(fp,PROCESSING_STRUCTURE,1)
448 header = numpy.fromfile(fp,PROCESSING_STRUCTURE,1)
449 self.size = int(header['nSize'][0])
449 self.size = int(header['nSize'][0])
450 self.dtype = int(header['nDataType'][0])
450 self.dtype = int(header['nDataType'][0])
451 self.blockSize = int(header['nSizeOfDataBlock'][0])
451 self.blockSize = int(header['nSizeOfDataBlock'][0])
452 self.profilesPerBlock = int(header['nProfilesperBlock'][0])
452 self.profilesPerBlock = int(header['nProfilesperBlock'][0])
453 self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0])
453 self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0])
454 self.nWindows = int(header['nNumWindows'][0])
454 self.nWindows = int(header['nNumWindows'][0])
455 self.processFlags = header['nProcessFlags']
455 self.processFlags = header['nProcessFlags']
456 self.nCohInt = int(header['nCoherentIntegrations'][0])
456 self.nCohInt = int(header['nCoherentIntegrations'][0])
457 self.nIncohInt = int(header['nIncoherentIntegrations'][0])
457 self.nIncohInt = int(header['nIncoherentIntegrations'][0])
458 self.totalSpectra = int(header['nTotalSpectra'][0])
458 self.totalSpectra = int(header['nTotalSpectra'][0])
459
459
460 self.samplingWindow = numpy.fromfile(fp,SAMPLING_STRUCTURE,self.nWindows)
460 self.samplingWindow = numpy.fromfile(fp,SAMPLING_STRUCTURE,self.nWindows)
461
461
462 self.nHeights = int(numpy.sum(self.samplingWindow['nsa']))
462 self.nHeights = int(numpy.sum(self.samplingWindow['nsa']))
463 self.firstHeight = float(self.samplingWindow['h0'][0])
463 self.firstHeight = float(self.samplingWindow['h0'][0])
464 self.deltaHeight = float(self.samplingWindow['dh'][0])
464 self.deltaHeight = float(self.samplingWindow['dh'][0])
465 self.samplesWin = self.samplingWindow['nsa'][0]
465 self.samplesWin = self.samplingWindow['nsa'][0]
466 self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra)
466 self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra)
467
467
468 # if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
468 # if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
469 # self.nCode = int(numpy.fromfile(fp,'<u4',1))
469 # self.nCode = int(numpy.fromfile(fp,'<u4',1))
470 # self.nBaud = int(numpy.fromfile(fp,'<u4',1))
470 # self.nBaud = int(numpy.fromfile(fp,'<u4',1))
471 # self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nCode,self.nBaud)
471 # self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nCode,self.nBaud)
472
472
473 if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA):
473 if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA):
474 self.shif_fft = True
474 self.shif_fft = True
475 else:
475 else:
476 self.shif_fft = False
476 self.shif_fft = False
477
477
478 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
478 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
479 self.flag_dc = True
479 self.flag_dc = True
480
480
481 nChannels = 0
481 nChannels = 0
482 nPairs = 0
482 nPairs = 0
483 pairList = []
483 pairList = []
484
484
485 for i in range( 0, self.totalSpectra*2, 2 ):
485 for i in range( 0, self.totalSpectra*2, 2 ):
486 if self.spectraComb[i] == self.spectraComb[i+1]:
486 if self.spectraComb[i] == self.spectraComb[i+1]:
487 nChannels = nChannels + 1 #par de canales iguales
487 nChannels = nChannels + 1 #par de canales iguales
488 else:
488 else:
489 nPairs = nPairs + 1 #par de canales diferentes
489 nPairs = nPairs + 1 #par de canales diferentes
490 pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) )
490 pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) )
491
491
492 self.flag_cspc = False
492 self.flag_cspc = False
493 if nPairs > 0:
493 if nPairs > 0:
494 self.flag_cspc = True
494 self.flag_cspc = True
495
495
496 # except Exception, e:
496 # except Exception, e:
497 # print "Error ProcessingHeader: "
497 # print "Error ProcessingHeader: "
498 # return 0
498 # return 0
499
499
500 return 1
500 return 1
501
501
502 def write(self, fp):
502 def write(self, fp):
503 headerTuple = (self.size,
503 headerTuple = (self.size,
504 self.dtype,
504 self.dtype,
505 self.blockSize,
505 self.blockSize,
506 self.profilesPerBlock,
506 self.profilesPerBlock,
507 self.dataBlocksPerFile,
507 self.dataBlocksPerFile,
508 self.nWindows,
508 self.nWindows,
509 self.processFlags,
509 self.processFlags,
510 self.nCohInt,
510 self.nCohInt,
511 self.nIncohInt,
511 self.nIncohInt,
512 self.totalSpectra)
512 self.totalSpectra)
513
513
514 header = numpy.array(headerTuple,PROCESSING_STRUCTURE)
514 header = numpy.array(headerTuple,PROCESSING_STRUCTURE)
515 header.tofile(fp)
515 header.tofile(fp)
516
516
517 if self.nWindows != 0:
517 if self.nWindows != 0:
518 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
518 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
519 samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE)
519 samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE)
520 samplingWindow.tofile(fp)
520 samplingWindow.tofile(fp)
521
521
522
522
523 if self.totalSpectra != 0:
523 if self.totalSpectra != 0:
524 spectraComb = numpy.array([],numpy.dtype('u1'))
524 spectraComb = numpy.array([],numpy.dtype('u1'))
525 spectraComb = self.spectraComb
525 spectraComb = self.spectraComb
526 spectraComb.tofile(fp)
526 spectraComb.tofile(fp)
527
527
528 # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
528 # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
529 # nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba
529 # nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba
530 # nCode.tofile(fp)
530 # nCode.tofile(fp)
531 #
531 #
532 # nBaud = numpy.array([self.nBaud], numpy.dtype('u4'))
532 # nBaud = numpy.array([self.nBaud], numpy.dtype('u4'))
533 # nBaud.tofile(fp)
533 # nBaud.tofile(fp)
534 #
534 #
535 # code = self.code.reshape(self.nCode*self.nBaud)
535 # code = self.code.reshape(self.nCode*self.nBaud)
536 # code = code.astype(numpy.dtype('<f4'))
536 # code = code.astype(numpy.dtype('<f4'))
537 # code.tofile(fp)
537 # code.tofile(fp)
538
538
539 return 1
539 return 1
540
540
541 class RCfunction:
541 class RCfunction:
542 NONE=0
542 NONE=0
543 FLIP=1
543 FLIP=1
544 CODE=2
544 CODE=2
545 SAMPLING=3
545 SAMPLING=3
546 LIN6DIV256=4
546 LIN6DIV256=4
547 SYNCHRO=5
547 SYNCHRO=5
548
548
549 class nCodeType:
549 class nCodeType:
550 NONE=0
550 NONE=0
551 USERDEFINE=1
551 USERDEFINE=1
552 BARKER2=2
552 BARKER2=2
553 BARKER3=3
553 BARKER3=3
554 BARKER4=4
554 BARKER4=4
555 BARKER5=5
555 BARKER5=5
556 BARKER7=6
556 BARKER7=6
557 BARKER11=7
557 BARKER11=7
558 BARKER13=8
558 BARKER13=8
559 AC128=9
559 AC128=9
560 COMPLEMENTARYCODE2=10
560 COMPLEMENTARYCODE2=10
561 COMPLEMENTARYCODE4=11
561 COMPLEMENTARYCODE4=11
562 COMPLEMENTARYCODE8=12
562 COMPLEMENTARYCODE8=12
563 COMPLEMENTARYCODE16=13
563 COMPLEMENTARYCODE16=13
564 COMPLEMENTARYCODE32=14
564 COMPLEMENTARYCODE32=14
565 COMPLEMENTARYCODE64=15
565 COMPLEMENTARYCODE64=15
566 COMPLEMENTARYCODE128=16
566 COMPLEMENTARYCODE128=16
567 CODE_BINARY28=17
567 CODE_BINARY28=17
568
568
569 class PROCFLAG:
569 class PROCFLAG:
570 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
570 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
571 DECODE_DATA = numpy.uint32(0x00000002)
571 DECODE_DATA = numpy.uint32(0x00000002)
572 SPECTRA_CALC = numpy.uint32(0x00000004)
572 SPECTRA_CALC = numpy.uint32(0x00000004)
573 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
573 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
574 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
574 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
575 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
575 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
576
576
577 DATATYPE_CHAR = numpy.uint32(0x00000040)
577 DATATYPE_CHAR = numpy.uint32(0x00000040)
578 DATATYPE_SHORT = numpy.uint32(0x00000080)
578 DATATYPE_SHORT = numpy.uint32(0x00000080)
579 DATATYPE_LONG = numpy.uint32(0x00000100)
579 DATATYPE_LONG = numpy.uint32(0x00000100)
580 DATATYPE_INT64 = numpy.uint32(0x00000200)
580 DATATYPE_INT64 = numpy.uint32(0x00000200)
581 DATATYPE_FLOAT = numpy.uint32(0x00000400)
581 DATATYPE_FLOAT = numpy.uint32(0x00000400)
582 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
582 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
583
583
584 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
584 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
585 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
585 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
586 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
586 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
587
587
588 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
588 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
589 DEFLIP_DATA = numpy.uint32(0x00010000)
589 DEFLIP_DATA = numpy.uint32(0x00010000)
590 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
590 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
591
591
592 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
592 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
593 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
593 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
594 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
594 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
595 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
595 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
596 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
596 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
597
597
598 EXP_NAME_ESP = numpy.uint32(0x00200000)
598 EXP_NAME_ESP = numpy.uint32(0x00200000)
599 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
599 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
600
600
601 OPERATION_MASK = numpy.uint32(0x0000003F)
601 OPERATION_MASK = numpy.uint32(0x0000003F)
602 DATATYPE_MASK = numpy.uint32(0x00000FC0)
602 DATATYPE_MASK = numpy.uint32(0x00000FC0)
603 DATAARRANGE_MASK = numpy.uint32(0x00007000)
603 DATAARRANGE_MASK = numpy.uint32(0x00007000)
604 ACQ_SYS_MASK = numpy.uint32(0x001C0000) No newline at end of file
604 ACQ_SYS_MASK = numpy.uint32(0x001C0000)
@@ -1,1196 +1,1148
1 '''
1 '''
2 @author: Daniel Suarez
2 @author: Daniel Suarez
3 '''
3 '''
4 import os
4 import os
5 import datetime
5 import datetime
6 import numpy
6 import numpy
7
7
8 from figure import Figure, isRealtime
8 from figure import Figure, isRealtime
9
9
10 class SpectraPlot(Figure):
10 class SpectraPlot(Figure):
11
11
12 isConfig = None
12 isConfig = None
13 __nsubplots = None
13 __nsubplots = None
14
14
15 WIDTHPROF = None
15 WIDTHPROF = None
16 HEIGHTPROF = None
16 HEIGHTPROF = None
17 PREFIX = 'spc'
17 PREFIX = 'spc'
18
18
19 def __init__(self):
19 def __init__(self):
20
20
21 self.isConfig = False
21 self.isConfig = False
22 self.__nsubplots = 1
22 self.__nsubplots = 1
23
23
24 self.WIDTH = 280
24 self.WIDTH = 280
25 self.HEIGHT = 250
25 self.HEIGHT = 250
26 self.WIDTHPROF = 120
26 self.WIDTHPROF = 120
27 self.HEIGHTPROF = 0
27 self.HEIGHTPROF = 0
28 self.counter_imagwr = 0
28 self.counter_imagwr = 0
29
29
30 self.PLOT_CODE = 1
30 self.PLOT_CODE = 1
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 def getSubplots(self):
36 def getSubplots(self):
37
37
38 ncol = int(numpy.sqrt(self.nplots)+0.9)
38 ncol = int(numpy.sqrt(self.nplots)+0.9)
39 nrow = int(self.nplots*1./ncol + 0.9)
39 nrow = int(self.nplots*1./ncol + 0.9)
40
40
41 return nrow, ncol
41 return nrow, ncol
42
42
43 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
43 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
44
44
45 self.__showprofile = showprofile
45 self.__showprofile = showprofile
46 self.nplots = nplots
46 self.nplots = nplots
47
47
48 ncolspan = 1
48 ncolspan = 1
49 colspan = 1
49 colspan = 1
50 if showprofile:
50 if showprofile:
51 ncolspan = 3
51 ncolspan = 3
52 colspan = 2
52 colspan = 2
53 self.__nsubplots = 2
53 self.__nsubplots = 2
54
54
55 self.createFigure(id = id,
55 self.createFigure(id = id,
56 wintitle = wintitle,
56 wintitle = wintitle,
57 widthplot = self.WIDTH + self.WIDTHPROF,
57 widthplot = self.WIDTH + self.WIDTHPROF,
58 heightplot = self.HEIGHT + self.HEIGHTPROF,
58 heightplot = self.HEIGHT + self.HEIGHTPROF,
59 show=show)
59 show=show)
60
60
61 nrow, ncol = self.getSubplots()
61 nrow, ncol = self.getSubplots()
62
62
63 counter = 0
63 counter = 0
64 for y in range(nrow):
64 for y in range(nrow):
65 for x in range(ncol):
65 for x in range(ncol):
66
66
67 if counter >= self.nplots:
67 if counter >= self.nplots:
68 break
68 break
69
69
70 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
70 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
71
71
72 if showprofile:
72 if showprofile:
73 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
73 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
74
74
75 counter += 1
75 counter += 1
76
76
77 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
77 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
78 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
78 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
79 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
79 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
80 server=None, folder=None, username=None, password=None,
80 server=None, folder=None, username=None, password=None,
81 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
81 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
82
82
83 """
83 """
84
84
85 Input:
85 Input:
86 dataOut :
86 dataOut :
87 id :
87 id :
88 wintitle :
88 wintitle :
89 channelList :
89 channelList :
90 showProfile :
90 showProfile :
91 xmin : None,
91 xmin : None,
92 xmax : None,
92 xmax : None,
93 ymin : None,
93 ymin : None,
94 ymax : None,
94 ymax : None,
95 zmin : None,
95 zmin : None,
96 zmax : None
96 zmax : None
97 """
97 """
98
98
99 if dataOut.flagNoData:
99 if dataOut.flagNoData:
100 return None
100 return 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"
113 raise ValueError, "Channel %d is not in dataOut.channelList"
114 channelIndexList.append(dataOut.channelList.index(channel))
114 channelIndexList.append(dataOut.channelList.index(channel))
115
115
116 factor = dataOut.normFactor
116 factor = dataOut.normFactor
117
117
118 x = dataOut.getVelRange(1)
118 x = dataOut.getVelRange(1)
119 y = dataOut.getHeiRange()
119 y = dataOut.getHeiRange()
120
120
121 z = dataOut.data_spc[channelIndexList,:,:]/factor
121 z = dataOut.data_spc[channelIndexList,:,:]/factor
122 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
122 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
123 avg = numpy.average(z, axis=1)
123 avg = numpy.average(z, axis=1)
124 avg = numpy.nanmean(z, axis=1)
124 avg = numpy.nanmean(z, axis=1)
125 noise = dataOut.noise/factor
125 noise = dataOut.noise/factor
126
126
127 zdB = 10*numpy.log10(z)
127 zdB = 10*numpy.log10(z)
128 avgdB = 10*numpy.log10(avg)
128 avgdB = 10*numpy.log10(avg)
129 noisedB = 10*numpy.log10(noise)
129 noisedB = 10*numpy.log10(noise)
130
130
131 #thisDatetime = dataOut.datatime
131 #thisDatetime = dataOut.datatime
132 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
132 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
133 title = wintitle + " Spectra"
133 title = wintitle + " Spectra"
134 xlabel = "Velocity (m/s)"
134 xlabel = "Velocity (m/s)"
135 ylabel = "Range (Km)"
135 ylabel = "Range (Km)"
136
136
137 if not self.isConfig:
137 if not self.isConfig:
138
138
139 nplots = len(channelIndexList)
139 nplots = len(channelIndexList)
140
140
141 self.setup(id=id,
141 self.setup(id=id,
142 nplots=nplots,
142 nplots=nplots,
143 wintitle=wintitle,
143 wintitle=wintitle,
144 showprofile=showprofile,
144 showprofile=showprofile,
145 show=show)
145 show=show)
146
146
147 if xmin == None: xmin = numpy.nanmin(x)
147 if xmin == None: xmin = numpy.nanmin(x)
148 if xmax == None: xmax = numpy.nanmax(x)
148 if xmax == None: xmax = numpy.nanmax(x)
149 if ymin == None: ymin = numpy.nanmin(y)
149 if ymin == None: ymin = numpy.nanmin(y)
150 if ymax == None: ymax = numpy.nanmax(y)
150 if ymax == None: ymax = numpy.nanmax(y)
151 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
151 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
152 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
152 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
153
153
154 self.FTP_WEI = ftp_wei
154 self.FTP_WEI = ftp_wei
155 self.EXP_CODE = exp_code
155 self.EXP_CODE = exp_code
156 self.SUB_EXP_CODE = sub_exp_code
156 self.SUB_EXP_CODE = sub_exp_code
157 self.PLOT_POS = plot_pos
157 self.PLOT_POS = plot_pos
158
158
159 self.isConfig = True
159 self.isConfig = True
160
160
161 self.setWinTitle(title)
161 self.setWinTitle(title)
162
162
163 for i in range(self.nplots):
163 for i in range(self.nplots):
164 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
164 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
165 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime)
165 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime)
166 axes = self.axesList[i*self.__nsubplots]
166 axes = self.axesList[i*self.__nsubplots]
167 axes.pcolor(x, y, zdB[i,:,:],
167 axes.pcolor(x, y, zdB[i,:,:],
168 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
168 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
169 xlabel=xlabel, ylabel=ylabel, title=title,
169 xlabel=xlabel, ylabel=ylabel, title=title,
170 ticksize=9, cblabel='')
170 ticksize=9, cblabel='')
171
171
172 if self.__showprofile:
172 if self.__showprofile:
173 axes = self.axesList[i*self.__nsubplots +1]
173 axes = self.axesList[i*self.__nsubplots +1]
174 axes.pline(avgdB[i], y,
174 axes.pline(avgdB[i], y,
175 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
175 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
176 xlabel='dB', ylabel='', title='',
176 xlabel='dB', ylabel='', title='',
177 ytick_visible=False,
177 ytick_visible=False,
178 grid='x')
178 grid='x')
179
179
180 noiseline = numpy.repeat(noisedB[i], len(y))
180 noiseline = numpy.repeat(noisedB[i], len(y))
181 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
181 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
182
182
183 self.draw()
183 self.draw()
184
184
185 if save:
185 if figfile == None:
186
186 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
187 figfile = self.getFilename(name = str_datetime)
188
189 if figpath != '':
187 self.counter_imagwr += 1
190 self.counter_imagwr += 1
188 if (self.counter_imagwr==wr_period):
191 if (self.counter_imagwr>=wr_period):
189 if figfile == None:
192 # store png plot to local folder
190 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
191 figfile = self.getFilename(name = str_datetime)
192
193 self.saveFigure(figpath, figfile)
193 self.saveFigure(figpath, figfile)
194
194 # store png plot to FTP server according to RT-Web format
195 if ftp:
195 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
196 #provisionalmente envia archivos en el formato de la web en tiempo real
196 ftp_filename = os.path.join(figpath, name)
197 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
197 self.saveFigure(figpath, ftp_filename)
198 path = '%s%03d' %(self.PREFIX, self.id)
199 ftp_file = os.path.join(path,'ftp','%s.png'%name)
200 self.saveFigure(figpath, ftp_file)
201 ftp_filename = os.path.join(figpath,ftp_file)
202 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
203 self.counter_imagwr = 0
204
205
206 self.counter_imagwr = 0
198 self.counter_imagwr = 0
207
199
200
208 class CrossSpectraPlot(Figure):
201 class CrossSpectraPlot(Figure):
209
202
210 isConfig = None
203 isConfig = None
211 __nsubplots = None
204 __nsubplots = None
212
205
213 WIDTH = None
206 WIDTH = None
214 HEIGHT = None
207 HEIGHT = None
215 WIDTHPROF = None
208 WIDTHPROF = None
216 HEIGHTPROF = None
209 HEIGHTPROF = None
217 PREFIX = 'cspc'
210 PREFIX = 'cspc'
218
211
219 def __init__(self):
212 def __init__(self):
220
213
221 self.isConfig = False
214 self.isConfig = False
222 self.__nsubplots = 4
215 self.__nsubplots = 4
223 self.counter_imagwr = 0
216 self.counter_imagwr = 0
224 self.WIDTH = 250
217 self.WIDTH = 250
225 self.HEIGHT = 250
218 self.HEIGHT = 250
226 self.WIDTHPROF = 0
219 self.WIDTHPROF = 0
227 self.HEIGHTPROF = 0
220 self.HEIGHTPROF = 0
228
221
229 self.PLOT_CODE = 1
222 self.PLOT_CODE = 1
230 self.FTP_WEI = None
223 self.FTP_WEI = None
231 self.EXP_CODE = None
224 self.EXP_CODE = None
232 self.SUB_EXP_CODE = None
225 self.SUB_EXP_CODE = None
233 self.PLOT_POS = None
226 self.PLOT_POS = None
234
227
235 def getSubplots(self):
228 def getSubplots(self):
236
229
237 ncol = 4
230 ncol = 4
238 nrow = self.nplots
231 nrow = self.nplots
239
232
240 return nrow, ncol
233 return nrow, ncol
241
234
242 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
235 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
243
236
244 self.__showprofile = showprofile
237 self.__showprofile = showprofile
245 self.nplots = nplots
238 self.nplots = nplots
246
239
247 ncolspan = 1
240 ncolspan = 1
248 colspan = 1
241 colspan = 1
249
242
250 self.createFigure(id = id,
243 self.createFigure(id = id,
251 wintitle = wintitle,
244 wintitle = wintitle,
252 widthplot = self.WIDTH + self.WIDTHPROF,
245 widthplot = self.WIDTH + self.WIDTHPROF,
253 heightplot = self.HEIGHT + self.HEIGHTPROF,
246 heightplot = self.HEIGHT + self.HEIGHTPROF,
254 show=True)
247 show=True)
255
248
256 nrow, ncol = self.getSubplots()
249 nrow, ncol = self.getSubplots()
257
250
258 counter = 0
251 counter = 0
259 for y in range(nrow):
252 for y in range(nrow):
260 for x in range(ncol):
253 for x in range(ncol):
261 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
254 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
262
255
263 counter += 1
256 counter += 1
264
257
265 def run(self, dataOut, id, wintitle="", pairsList=None,
258 def run(self, dataOut, id, wintitle="", pairsList=None,
266 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
259 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
267 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
260 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
268 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
261 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
269 server=None, folder=None, username=None, password=None,
262 server=None, folder=None, username=None, password=None,
270 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
263 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
271
264
272 """
265 """
273
266
274 Input:
267 Input:
275 dataOut :
268 dataOut :
276 id :
269 id :
277 wintitle :
270 wintitle :
278 channelList :
271 channelList :
279 showProfile :
272 showProfile :
280 xmin : None,
273 xmin : None,
281 xmax : None,
274 xmax : None,
282 ymin : None,
275 ymin : None,
283 ymax : None,
276 ymax : None,
284 zmin : None,
277 zmin : None,
285 zmax : None
278 zmax : None
286 """
279 """
287
280
288 if pairsList == None:
281 if pairsList == None:
289 pairsIndexList = dataOut.pairsIndexList
282 pairsIndexList = dataOut.pairsIndexList
290 else:
283 else:
291 pairsIndexList = []
284 pairsIndexList = []
292 for pair in pairsList:
285 for pair in pairsList:
293 if pair not in dataOut.pairsList:
286 if pair not in dataOut.pairsList:
294 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
287 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
295 pairsIndexList.append(dataOut.pairsList.index(pair))
288 pairsIndexList.append(dataOut.pairsList.index(pair))
296
289
297 if pairsIndexList == []:
290 if pairsIndexList == []:
298 return
291 return
299
292
300 if len(pairsIndexList) > 4:
293 if len(pairsIndexList) > 4:
301 pairsIndexList = pairsIndexList[0:4]
294 pairsIndexList = pairsIndexList[0:4]
302 factor = dataOut.normFactor
295 factor = dataOut.normFactor
303 x = dataOut.getVelRange(1)
296 x = dataOut.getVelRange(1)
304 y = dataOut.getHeiRange()
297 y = dataOut.getHeiRange()
305 z = dataOut.data_spc[:,:,:]/factor
298 z = dataOut.data_spc[:,:,:]/factor
306 # z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
299 # z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
307 avg = numpy.abs(numpy.average(z, axis=1))
300 avg = numpy.abs(numpy.average(z, axis=1))
308 noise = dataOut.noise()/factor
301 noise = dataOut.noise()/factor
309
302
310 zdB = 10*numpy.log10(z)
303 zdB = 10*numpy.log10(z)
311 avgdB = 10*numpy.log10(avg)
304 avgdB = 10*numpy.log10(avg)
312 noisedB = 10*numpy.log10(noise)
305 noisedB = 10*numpy.log10(noise)
313
306
314
307
315 #thisDatetime = dataOut.datatime
308 #thisDatetime = dataOut.datatime
316 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
309 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
317 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
310 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
318 xlabel = "Velocity (m/s)"
311 xlabel = "Velocity (m/s)"
319 ylabel = "Range (Km)"
312 ylabel = "Range (Km)"
320
313
321 if not self.isConfig:
314 if not self.isConfig:
322
315
323 nplots = len(pairsIndexList)
316 nplots = len(pairsIndexList)
324
317
325 self.setup(id=id,
318 self.setup(id=id,
326 nplots=nplots,
319 nplots=nplots,
327 wintitle=wintitle,
320 wintitle=wintitle,
328 showprofile=False,
321 showprofile=False,
329 show=show)
322 show=show)
330
323
331 if xmin == None: xmin = numpy.nanmin(x)
324 if xmin == None: xmin = numpy.nanmin(x)
332 if xmax == None: xmax = numpy.nanmax(x)
325 if xmax == None: xmax = numpy.nanmax(x)
333 if ymin == None: ymin = numpy.nanmin(y)
326 if ymin == None: ymin = numpy.nanmin(y)
334 if ymax == None: ymax = numpy.nanmax(y)
327 if ymax == None: ymax = numpy.nanmax(y)
335 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
328 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
336 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
329 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
337
330
338 self.FTP_WEI = ftp_wei
331 self.FTP_WEI = ftp_wei
339 self.EXP_CODE = exp_code
332 self.EXP_CODE = exp_code
340 self.SUB_EXP_CODE = sub_exp_code
333 self.SUB_EXP_CODE = sub_exp_code
341 self.PLOT_POS = plot_pos
334 self.PLOT_POS = plot_pos
342
335
343 self.isConfig = True
336 self.isConfig = True
344
337
345 self.setWinTitle(title)
338 self.setWinTitle(title)
346
339
347 for i in range(self.nplots):
340 for i in range(self.nplots):
348 pair = dataOut.pairsList[pairsIndexList[i]]
341 pair = dataOut.pairsList[pairsIndexList[i]]
349 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
342 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
350 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[pair[0]], str_datetime)
343 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[pair[0]], str_datetime)
351 zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor)
344 zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor)
352 axes0 = self.axesList[i*self.__nsubplots]
345 axes0 = self.axesList[i*self.__nsubplots]
353 axes0.pcolor(x, y, zdB,
346 axes0.pcolor(x, y, zdB,
354 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
347 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
355 xlabel=xlabel, ylabel=ylabel, title=title,
348 xlabel=xlabel, ylabel=ylabel, title=title,
356 ticksize=9, colormap=power_cmap, cblabel='')
349 ticksize=9, colormap=power_cmap, cblabel='')
357
350
358 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[pair[1]], str_datetime)
351 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[pair[1]], str_datetime)
359 zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor)
352 zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor)
360 axes0 = self.axesList[i*self.__nsubplots+1]
353 axes0 = self.axesList[i*self.__nsubplots+1]
361 axes0.pcolor(x, y, zdB,
354 axes0.pcolor(x, y, zdB,
362 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
355 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
363 xlabel=xlabel, ylabel=ylabel, title=title,
356 xlabel=xlabel, ylabel=ylabel, title=title,
364 ticksize=9, colormap=power_cmap, cblabel='')
357 ticksize=9, colormap=power_cmap, cblabel='')
365
358
366 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
359 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
367 coherence = numpy.abs(coherenceComplex)
360 coherence = numpy.abs(coherenceComplex)
368 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
361 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
369 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
362 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
370
363
371 title = "Coherence %d%d" %(pair[0], pair[1])
364 title = "Coherence %d%d" %(pair[0], pair[1])
372 axes0 = self.axesList[i*self.__nsubplots+2]
365 axes0 = self.axesList[i*self.__nsubplots+2]
373 axes0.pcolor(x, y, coherence,
366 axes0.pcolor(x, y, coherence,
374 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
367 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
375 xlabel=xlabel, ylabel=ylabel, title=title,
368 xlabel=xlabel, ylabel=ylabel, title=title,
376 ticksize=9, colormap=coherence_cmap, cblabel='')
369 ticksize=9, colormap=coherence_cmap, cblabel='')
377
370
378 title = "Phase %d%d" %(pair[0], pair[1])
371 title = "Phase %d%d" %(pair[0], pair[1])
379 axes0 = self.axesList[i*self.__nsubplots+3]
372 axes0 = self.axesList[i*self.__nsubplots+3]
380 axes0.pcolor(x, y, phase,
373 axes0.pcolor(x, y, phase,
381 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
374 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
382 xlabel=xlabel, ylabel=ylabel, title=title,
375 xlabel=xlabel, ylabel=ylabel, title=title,
383 ticksize=9, colormap=phase_cmap, cblabel='')
376 ticksize=9, colormap=phase_cmap, cblabel='')
384
377
385
378
386
379
387 self.draw()
380 self.draw()
388
381
389 if save:
382 if save:
390
383
391 self.counter_imagwr += 1
384 self.counter_imagwr += 1
392 if (self.counter_imagwr==wr_period):
385 if (self.counter_imagwr==wr_period):
393 if figfile == None:
386 if figfile == None:
394 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
387 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
395 figfile = self.getFilename(name = str_datetime)
388 figfile = self.getFilename(name = str_datetime)
396
389
397 self.saveFigure(figpath, figfile)
390 self.saveFigure(figpath, figfile)
398
391
399 if ftp:
392 if ftp:
400 #provisionalmente envia archivos en el formato de la web en tiempo real
393 #provisionalmente envia archivos en el formato de la web en tiempo real
401 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
394 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
402 path = '%s%03d' %(self.PREFIX, self.id)
395 path = '%s%03d' %(self.PREFIX, self.id)
403 ftp_file = os.path.join(path,'ftp','%s.png'%name)
396 ftp_file = os.path.join(path,'ftp','%s.png'%name)
404 self.saveFigure(figpath, ftp_file)
397 self.saveFigure(figpath, ftp_file)
405 ftp_filename = os.path.join(figpath,ftp_file)
398 ftp_filename = os.path.join(figpath,ftp_file)
406
399
407 try:
400 try:
408 self.sendByFTP(ftp_filename, server, folder, username, password)
401 self.sendByFTP(ftp_filename, server, folder, username, password)
409 except:
402 except:
410 self.counter_imagwr = 0
403 self.counter_imagwr = 0
411 print ValueError, 'Error FTP'
404 print ValueError, 'Error FTP'
412
405
413 self.counter_imagwr = 0
406 self.counter_imagwr = 0
414
407
415 class RTIPlot(Figure):
408 class RTIPlot(Figure):
416
409
417 isConfig = None
410 isConfig = None
418 __nsubplots = None
411 __nsubplots = None
419
412
420 WIDTHPROF = None
413 WIDTHPROF = None
421 HEIGHTPROF = None
414 HEIGHTPROF = None
422 PREFIX = 'rti'
415 PREFIX = 'rti'
423
416
424 def __init__(self):
417 def __init__(self):
425
418
426 self.timerange = 2*60*60
419 self.timerange = 2*60*60
427 self.isConfig = False
420 self.isConfig = False
428 self.__nsubplots = 1
421 self.__nsubplots = 1
429
422
430 self.WIDTH = 800
423 self.WIDTH = 800
431 self.HEIGHT = 150
424 self.HEIGHT = 150
432 self.WIDTHPROF = 120
425 self.WIDTHPROF = 120
433 self.HEIGHTPROF = 0
426 self.HEIGHTPROF = 0
434 self.counter_imagwr = 0
427 self.counter_imagwr = 0
435
428
436 self.PLOT_CODE = 0
429 self.PLOT_CODE = 0
437 self.FTP_WEI = None
430 self.FTP_WEI = None
438 self.EXP_CODE = None
431 self.EXP_CODE = None
439 self.SUB_EXP_CODE = None
432 self.SUB_EXP_CODE = None
440 self.PLOT_POS = None
433 self.PLOT_POS = None
441 self.tmin = None
434 self.tmin = None
442 self.tmax = None
435 self.tmax = None
443
436
444 self.xmin = None
437 self.xmin = None
445 self.xmax = None
438 self.xmax = None
446
439
447 def getSubplots(self):
440 def getSubplots(self):
448
441
449 ncol = 1
442 ncol = 1
450 nrow = self.nplots
443 nrow = self.nplots
451
444
452 return nrow, ncol
445 return nrow, ncol
453
446
454 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
447 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
455
448
456 self.__showprofile = showprofile
449 self.__showprofile = showprofile
457 self.nplots = nplots
450 self.nplots = nplots
458
451
459 ncolspan = 1
452 ncolspan = 1
460 colspan = 1
453 colspan = 1
461 if showprofile:
454 if showprofile:
462 ncolspan = 7
455 ncolspan = 7
463 colspan = 6
456 colspan = 6
464 self.__nsubplots = 2
457 self.__nsubplots = 2
465
458
466 self.createFigure(id = id,
459 self.createFigure(id = id,
467 wintitle = wintitle,
460 wintitle = wintitle,
468 widthplot = self.WIDTH + self.WIDTHPROF,
461 widthplot = self.WIDTH + self.WIDTHPROF,
469 heightplot = self.HEIGHT + self.HEIGHTPROF,
462 heightplot = self.HEIGHT + self.HEIGHTPROF,
470 show=show)
463 show=show)
471
464
472 nrow, ncol = self.getSubplots()
465 nrow, ncol = self.getSubplots()
473
466
474 counter = 0
467 counter = 0
475 for y in range(nrow):
468 for y in range(nrow):
476 for x in range(ncol):
469 for x in range(ncol):
477
470
478 if counter >= self.nplots:
471 if counter >= self.nplots:
479 break
472 break
480
473
481 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
474 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
482
475
483 if showprofile:
476 if showprofile:
484 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
477 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
485
478
486 counter += 1
479 counter += 1
487
480
488 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
481 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
489 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
482 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
490 timerange=None,
483 timerange=None,
491 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
484 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
492 server=None, folder=None, username=None, password=None,
485 server=None, folder=None, username=None, password=None,
493 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
486 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
494
487
495 """
488 """
496
489
497 Input:
490 Input:
498 dataOut :
491 dataOut :
499 id :
492 id :
500 wintitle :
493 wintitle :
501 channelList :
494 channelList :
502 showProfile :
495 showProfile :
503 xmin : None,
496 xmin : None,
504 xmax : None,
497 xmax : None,
505 ymin : None,
498 ymin : None,
506 ymax : None,
499 ymax : None,
507 zmin : None,
500 zmin : None,
508 zmax : None
501 zmax : None
509 """
502 """
510
503
511 if channelList == None:
504 if channelList == None:
512 channelIndexList = dataOut.channelIndexList
505 channelIndexList = dataOut.channelIndexList
513 else:
506 else:
514 channelIndexList = []
507 channelIndexList = []
515 for channel in channelList:
508 for channel in channelList:
516 if channel not in dataOut.channelList:
509 if channel not in dataOut.channelList:
517 raise ValueError, "Channel %d is not in dataOut.channelList"
510 raise ValueError, "Channel %d is not in dataOut.channelList"
518 channelIndexList.append(dataOut.channelList.index(channel))
511 channelIndexList.append(dataOut.channelList.index(channel))
519
512
520 if timerange != None:
513 if timerange != None:
521 self.timerange = timerange
514 self.timerange = timerange
522
515
523 #tmin = None
516 #tmin = None
524 #tmax = None
517 #tmax = None
525 factor = dataOut.normFactor
518 factor = dataOut.normFactor
526 x = dataOut.getTimeRange()
519 x = dataOut.getTimeRange()
527 y = dataOut.getHeiRange()
520 y = dataOut.getHeiRange()
528
521
529 z = dataOut.data_spc[channelIndexList,:,:]/factor
522 z = dataOut.data_spc[channelIndexList,:,:]/factor
530 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
523 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
531 avg = numpy.average(z, axis=1)
524 avg = numpy.average(z, axis=1)
532
525
533 avgdB = 10.*numpy.log10(avg)
526 avgdB = 10.*numpy.log10(avg)
534
527
535
528
536 # thisDatetime = dataOut.datatime
529 # thisDatetime = dataOut.datatime
537 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
530 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
538 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
531 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
539 xlabel = ""
532 xlabel = ""
540 ylabel = "Range (Km)"
533 ylabel = "Range (Km)"
541
534
542 if not self.isConfig:
535 if not self.isConfig:
543
536
544 nplots = len(channelIndexList)
537 nplots = len(channelIndexList)
545
538
546 self.setup(id=id,
539 self.setup(id=id,
547 nplots=nplots,
540 nplots=nplots,
548 wintitle=wintitle,
541 wintitle=wintitle,
549 showprofile=showprofile,
542 showprofile=showprofile,
550 show=show)
543 show=show)
551
544
552 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
545 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
553
546
554 # if timerange != None:
547 # if timerange != None:
555 # self.timerange = timerange
548 # self.timerange = timerange
556 # self.xmin, self.tmax = self.getTimeLim(x, xmin, xmax, timerange)
549 # self.xmin, self.tmax = self.getTimeLim(x, xmin, xmax, timerange)
557
550
558
551
559
552
560 if ymin == None: ymin = numpy.nanmin(y)
553 if ymin == None: ymin = numpy.nanmin(y)
561 if ymax == None: ymax = numpy.nanmax(y)
554 if ymax == None: ymax = numpy.nanmax(y)
562 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
555 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
563 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
556 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
564
557
565 self.FTP_WEI = ftp_wei
558 self.FTP_WEI = ftp_wei
566 self.EXP_CODE = exp_code
559 self.EXP_CODE = exp_code
567 self.SUB_EXP_CODE = sub_exp_code
560 self.SUB_EXP_CODE = sub_exp_code
568 self.PLOT_POS = plot_pos
561 self.PLOT_POS = plot_pos
569
562
570 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
563 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
571 self.isConfig = True
564 self.isConfig = True
572
565
573
566
574 self.setWinTitle(title)
567 self.setWinTitle(title)
575
568
576 if ((self.xmax - x[1]) < (x[1]-x[0])):
569 if ((self.xmax - x[1]) < (x[1]-x[0])):
577 x[1] = self.xmax
570 x[1] = self.xmax
578
571
579 for i in range(self.nplots):
572 for i in range(self.nplots):
580 title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
573 title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
581 axes = self.axesList[i*self.__nsubplots]
574 axes = self.axesList[i*self.__nsubplots]
582 zdB = avgdB[i].reshape((1,-1))
575 zdB = avgdB[i].reshape((1,-1))
583 axes.pcolorbuffer(x, y, zdB,
576 axes.pcolorbuffer(x, y, zdB,
584 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
577 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
585 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
578 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
586 ticksize=9, cblabel='', cbsize="1%")
579 ticksize=9, cblabel='', cbsize="1%")
587
580
588 if self.__showprofile:
581 if self.__showprofile:
589 axes = self.axesList[i*self.__nsubplots +1]
582 axes = self.axesList[i*self.__nsubplots +1]
590 axes.pline(avgdB[i], y,
583 axes.pline(avgdB[i], y,
591 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
584 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
592 xlabel='dB', ylabel='', title='',
585 xlabel='dB', ylabel='', title='',
593 ytick_visible=False,
586 ytick_visible=False,
594 grid='x')
587 grid='x')
595
588
596 self.draw()
589 self.draw()
597
590
598 # if lastone:
599 # if dataOut.blocknow >= dataOut.last_block:
600 # if figfile == None:
601 # figfile = self.getFilename(name = self.name)
602 # self.saveFigure(figpath, figfile)
603 #
604 # if (save and not(lastone)):
605 #
606 # self.counter_imagwr += 1
607 # if (self.counter_imagwr==wr_period):
608 # if figfile == None:
609 # figfile = self.getFilename(name = self.name)
610 # self.saveFigure(figpath, figfile)
611 #
612 # if ftp:
613 # #provisionalmente envia archivos en el formato de la web en tiempo real
614 # name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
615 # path = '%s%03d' %(self.PREFIX, self.id)
616 # ftp_file = os.path.join(path,'ftp','%s.png'%name)
617 # self.saveFigure(figpath, ftp_file)
618 # ftp_filename = os.path.join(figpath,ftp_file)
619 # self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
620 # self.counter_imagwr = 0
621 #
622 # self.counter_imagwr = 0
623
624 #if ((dataOut.utctime-time.timezone) >= self.axesList[0].xmax):
625 self.saveFigure(figpath, figfile)
626 if x[1] >= self.axesList[0].xmax:
591 if x[1] >= self.axesList[0].xmax:
627 self.saveFigure(figpath, figfile)
592 self.counter_imagwr = wr_period
628 self.isConfig = False
593 self.__isConfig = False
594
595 if figfile == None:
596 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
597 figfile = self.getFilename(name = str_datetime)
598
599 if figpath != '':
629
600
630 # if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
601 self.counter_imagwr += 1
631 #
602 if (self.counter_imagwr>=wr_period):
632 # self.isConfig = False
603 # store png plot to local folder
633
604 self.saveFigure(figpath, figfile)
634 # if lastone:
605 # store png plot to FTP server according to RT-Web format
635 # if figfile == None:
606 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
636 # figfile = self.getFilename(name = self.name)
607 ftp_filename = os.path.join(figpath, name)
637 # self.saveFigure(figpath, figfile)
608 self.saveFigure(figpath, ftp_filename)
638 #
609
639 # if ftp:
610 self.counter_imagwr = 0
640 # #provisionalmente envia archivos en el formato de la web en tiempo real
611
641 # name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
642 # path = '%s%03d' %(self.PREFIX, self.id)
643 # ftp_file = os.path.join(path,'ftp','%s.png'%name)
644 # self.saveFigure(figpath, ftp_file)
645 # ftp_filename = os.path.join(figpath,ftp_file)
646 # self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
647
612
648 class CoherenceMap(Figure):
613 class CoherenceMap(Figure):
649 isConfig = None
614 isConfig = None
650 __nsubplots = None
615 __nsubplots = None
651
616
652 WIDTHPROF = None
617 WIDTHPROF = None
653 HEIGHTPROF = None
618 HEIGHTPROF = None
654 PREFIX = 'cmap'
619 PREFIX = 'cmap'
655
620
656 def __init__(self):
621 def __init__(self):
657 self.timerange = 2*60*60
622 self.timerange = 2*60*60
658 self.isConfig = False
623 self.isConfig = False
659 self.__nsubplots = 1
624 self.__nsubplots = 1
660
625
661 self.WIDTH = 800
626 self.WIDTH = 800
662 self.HEIGHT = 150
627 self.HEIGHT = 150
663 self.WIDTHPROF = 120
628 self.WIDTHPROF = 120
664 self.HEIGHTPROF = 0
629 self.HEIGHTPROF = 0
665 self.counter_imagwr = 0
630 self.counter_imagwr = 0
666
631
667 self.PLOT_CODE = 3
632 self.PLOT_CODE = 3
668 self.FTP_WEI = None
633 self.FTP_WEI = None
669 self.EXP_CODE = None
634 self.EXP_CODE = None
670 self.SUB_EXP_CODE = None
635 self.SUB_EXP_CODE = None
671 self.PLOT_POS = None
636 self.PLOT_POS = None
672 self.counter_imagwr = 0
637 self.counter_imagwr = 0
673
638
674 self.xmin = None
639 self.xmin = None
675 self.xmax = None
640 self.xmax = None
676
641
677 def getSubplots(self):
642 def getSubplots(self):
678 ncol = 1
643 ncol = 1
679 nrow = self.nplots*2
644 nrow = self.nplots*2
680
645
681 return nrow, ncol
646 return nrow, ncol
682
647
683 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
648 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
684 self.__showprofile = showprofile
649 self.__showprofile = showprofile
685 self.nplots = nplots
650 self.nplots = nplots
686
651
687 ncolspan = 1
652 ncolspan = 1
688 colspan = 1
653 colspan = 1
689 if showprofile:
654 if showprofile:
690 ncolspan = 7
655 ncolspan = 7
691 colspan = 6
656 colspan = 6
692 self.__nsubplots = 2
657 self.__nsubplots = 2
693
658
694 self.createFigure(id = id,
659 self.createFigure(id = id,
695 wintitle = wintitle,
660 wintitle = wintitle,
696 widthplot = self.WIDTH + self.WIDTHPROF,
661 widthplot = self.WIDTH + self.WIDTHPROF,
697 heightplot = self.HEIGHT + self.HEIGHTPROF,
662 heightplot = self.HEIGHT + self.HEIGHTPROF,
698 show=True)
663 show=True)
699
664
700 nrow, ncol = self.getSubplots()
665 nrow, ncol = self.getSubplots()
701
666
702 for y in range(nrow):
667 for y in range(nrow):
703 for x in range(ncol):
668 for x in range(ncol):
704
669
705 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
670 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
706
671
707 if showprofile:
672 if showprofile:
708 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
673 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
709
674
710 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
675 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
711 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
676 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
712 timerange=None,
677 timerange=None,
713 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
678 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
714 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
679 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
715 server=None, folder=None, username=None, password=None,
680 server=None, folder=None, username=None, password=None,
716 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
681 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
717
682
718 if pairsList == None:
683 if pairsList == None:
719 pairsIndexList = dataOut.pairsIndexList
684 pairsIndexList = dataOut.pairsIndexList
720 else:
685 else:
721 pairsIndexList = []
686 pairsIndexList = []
722 for pair in pairsList:
687 for pair in pairsList:
723 if pair not in dataOut.pairsList:
688 if pair not in dataOut.pairsList:
724 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
689 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
725 pairsIndexList.append(dataOut.pairsList.index(pair))
690 pairsIndexList.append(dataOut.pairsList.index(pair))
726
691
727 if timerange != None:
692 if timerange != None:
728 self.timerange = timerange
693 self.timerange = timerange
729
694
730 if pairsIndexList == []:
695 if pairsIndexList == []:
731 return
696 return
732
697
733 if len(pairsIndexList) > 4:
698 if len(pairsIndexList) > 4:
734 pairsIndexList = pairsIndexList[0:4]
699 pairsIndexList = pairsIndexList[0:4]
735
700
736 # tmin = None
701 # tmin = None
737 # tmax = None
702 # tmax = None
738 x = dataOut.getTimeRange()
703 x = dataOut.getTimeRange()
739 y = dataOut.getHeiRange()
704 y = dataOut.getHeiRange()
740
705
741 #thisDatetime = dataOut.datatime
706 #thisDatetime = dataOut.datatime
742 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
707 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
743 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
708 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
744 xlabel = ""
709 xlabel = ""
745 ylabel = "Range (Km)"
710 ylabel = "Range (Km)"
746
711
747 if not self.isConfig:
712 if not self.isConfig:
748 nplots = len(pairsIndexList)
713 nplots = len(pairsIndexList)
749 self.setup(id=id,
714 self.setup(id=id,
750 nplots=nplots,
715 nplots=nplots,
751 wintitle=wintitle,
716 wintitle=wintitle,
752 showprofile=showprofile,
717 showprofile=showprofile,
753 show=show)
718 show=show)
754
719
755 #tmin, tmax = self.getTimeLim(x, xmin, xmax)
720 #tmin, tmax = self.getTimeLim(x, xmin, xmax)
756
721
757 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
722 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
758
723
759 if ymin == None: ymin = numpy.nanmin(y)
724 if ymin == None: ymin = numpy.nanmin(y)
760 if ymax == None: ymax = numpy.nanmax(y)
725 if ymax == None: ymax = numpy.nanmax(y)
761 if zmin == None: zmin = 0.
726 if zmin == None: zmin = 0.
762 if zmax == None: zmax = 1.
727 if zmax == None: zmax = 1.
763
728
764 self.FTP_WEI = ftp_wei
729 self.FTP_WEI = ftp_wei
765 self.EXP_CODE = exp_code
730 self.EXP_CODE = exp_code
766 self.SUB_EXP_CODE = sub_exp_code
731 self.SUB_EXP_CODE = sub_exp_code
767 self.PLOT_POS = plot_pos
732 self.PLOT_POS = plot_pos
768
733
769 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
734 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
770
735
771 self.isConfig = True
736 self.isConfig = True
772
737
773 self.setWinTitle(title)
738 self.setWinTitle(title)
774
739
775 if ((self.xmax - x[1]) < (x[1]-x[0])):
740 if ((self.xmax - x[1]) < (x[1]-x[0])):
776 x[1] = self.xmax
741 x[1] = self.xmax
777
742
778 for i in range(self.nplots):
743 for i in range(self.nplots):
779
744
780 pair = dataOut.pairsList[pairsIndexList[i]]
745 pair = dataOut.pairsList[pairsIndexList[i]]
781 # coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
782 # avgcoherenceComplex = numpy.average(coherenceComplex, axis=0)
783 # coherence = numpy.abs(avgcoherenceComplex)
784
785 ## coherence = numpy.abs(coherenceComplex)
786 ## avg = numpy.average(coherence, axis=0)
787
746
788 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
747 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
789 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
748 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
790 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
749 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
791
750
792
751
793 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
752 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
794 coherence = numpy.abs(avgcoherenceComplex)
753 coherence = numpy.abs(avgcoherenceComplex)
795
754
796 z = coherence.reshape((1,-1))
755 z = coherence.reshape((1,-1))
797
756
798 counter = 0
757 counter = 0
799
758
800 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
759 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
801 axes = self.axesList[i*self.__nsubplots*2]
760 axes = self.axesList[i*self.__nsubplots*2]
802 axes.pcolorbuffer(x, y, z,
761 axes.pcolorbuffer(x, y, z,
803 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
762 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
804 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
763 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
805 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
764 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
806
765
807 if self.__showprofile:
766 if self.__showprofile:
808 counter += 1
767 counter += 1
809 axes = self.axesList[i*self.__nsubplots*2 + counter]
768 axes = self.axesList[i*self.__nsubplots*2 + counter]
810 axes.pline(coherence, y,
769 axes.pline(coherence, y,
811 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
770 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
812 xlabel='', ylabel='', title='', ticksize=7,
771 xlabel='', ylabel='', title='', ticksize=7,
813 ytick_visible=False, nxticks=5,
772 ytick_visible=False, nxticks=5,
814 grid='x')
773 grid='x')
815
774
816 counter += 1
775 counter += 1
817 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
776
818 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
777 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
819 # avg = numpy.average(phase, axis=0)
778
820 z = phase.reshape((1,-1))
779 z = phase.reshape((1,-1))
821
780
822 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
781 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
823 axes = self.axesList[i*self.__nsubplots*2 + counter]
782 axes = self.axesList[i*self.__nsubplots*2 + counter]
824 axes.pcolorbuffer(x, y, z,
783 axes.pcolorbuffer(x, y, z,
825 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
784 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
826 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
785 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
827 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
786 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
828
787
829 if self.__showprofile:
788 if self.__showprofile:
830 counter += 1
789 counter += 1
831 axes = self.axesList[i*self.__nsubplots*2 + counter]
790 axes = self.axesList[i*self.__nsubplots*2 + counter]
832 axes.pline(phase, y,
791 axes.pline(phase, y,
833 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
792 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
834 xlabel='', ylabel='', title='', ticksize=7,
793 xlabel='', ylabel='', title='', ticksize=7,
835 ytick_visible=False, nxticks=4,
794 ytick_visible=False, nxticks=4,
836 grid='x')
795 grid='x')
837
796
838 self.draw()
797 self.draw()
839
798
840 if x[1] >= self.axesList[0].xmax:
799 if x[1] >= self.axesList[0].xmax:
841 self.saveFigure(figpath, figfile)
800 self.counter_imagwr = wr_period
842 self.isConfig = False
801 self.__isConfig = False
843
802
844 # if save:
803 if figfile == None:
845 #
804 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
846 # self.counter_imagwr += 1
805 figfile = self.getFilename(name = str_datetime)
847 # if (self.counter_imagwr==wr_period):
806
848 # if figfile == None:
807 if figpath != '':
849 # figfile = self.getFilename(name = self.name)
808
850 # self.saveFigure(figpath, figfile)
809 self.counter_imagwr += 1
851 #
810 if (self.counter_imagwr>=wr_period):
852 # if ftp:
811 # store png plot to local folder
853 # #provisionalmente envia archivos en el formato de la web en tiempo real
812 self.saveFigure(figpath, figfile)
854 # name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
813 # store png plot to FTP server according to RT-Web format
855 # path = '%s%03d' %(self.PREFIX, self.id)
814 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
856 # ftp_file = os.path.join(path,'ftp','%s.png'%name)
815 ftp_filename = os.path.join(figpath, name)
857 # self.saveFigure(figpath, ftp_file)
816 self.saveFigure(figpath, ftp_filename)
858 # ftp_filename = os.path.join(figpath,ftp_file)
817
859 # self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
818 self.counter_imagwr = 0
860 # self.counter_imagwr = 0
861 #
862 # self.counter_imagwr = 0
863 #
864 #
865 # if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
866 # self.isConfig = False
867
819
868 class PowerProfile(Figure):
820 class PowerProfile(Figure):
869 isConfig = None
821 isConfig = None
870 __nsubplots = None
822 __nsubplots = None
871
823
872 WIDTHPROF = None
824 WIDTHPROF = None
873 HEIGHTPROF = None
825 HEIGHTPROF = None
874 PREFIX = 'spcprofile'
826 PREFIX = 'spcprofile'
875
827
876 def __init__(self):
828 def __init__(self):
877 self.isConfig = False
829 self.isConfig = False
878 self.__nsubplots = 1
830 self.__nsubplots = 1
879
831
880 self.WIDTH = 300
832 self.WIDTH = 300
881 self.HEIGHT = 500
833 self.HEIGHT = 500
882 self.counter_imagwr = 0
834 self.counter_imagwr = 0
883
835
884 def getSubplots(self):
836 def getSubplots(self):
885 ncol = 1
837 ncol = 1
886 nrow = 1
838 nrow = 1
887
839
888 return nrow, ncol
840 return nrow, ncol
889
841
890 def setup(self, id, nplots, wintitle, show):
842 def setup(self, id, nplots, wintitle, show):
891
843
892 self.nplots = nplots
844 self.nplots = nplots
893
845
894 ncolspan = 1
846 ncolspan = 1
895 colspan = 1
847 colspan = 1
896
848
897 self.createFigure(id = id,
849 self.createFigure(id = id,
898 wintitle = wintitle,
850 wintitle = wintitle,
899 widthplot = self.WIDTH,
851 widthplot = self.WIDTH,
900 heightplot = self.HEIGHT,
852 heightplot = self.HEIGHT,
901 show=show)
853 show=show)
902
854
903 nrow, ncol = self.getSubplots()
855 nrow, ncol = self.getSubplots()
904
856
905 counter = 0
857 counter = 0
906 for y in range(nrow):
858 for y in range(nrow):
907 for x in range(ncol):
859 for x in range(ncol):
908 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
860 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
909
861
910 def run(self, dataOut, id, wintitle="", channelList=None,
862 def run(self, dataOut, id, wintitle="", channelList=None,
911 xmin=None, xmax=None, ymin=None, ymax=None,
863 xmin=None, xmax=None, ymin=None, ymax=None,
912 save=False, figpath='./', figfile=None, show=True, wr_period=1,
864 save=False, figpath='./', figfile=None, show=True, wr_period=1,
913 server=None, folder=None, username=None, password=None,):
865 server=None, folder=None, username=None, password=None,):
914
866
915 if dataOut.flagNoData:
867 if dataOut.flagNoData:
916 return None
868 return None
917
869
918 if channelList == None:
870 if channelList == None:
919 channelIndexList = dataOut.channelIndexList
871 channelIndexList = dataOut.channelIndexList
920 channelList = dataOut.channelList
872 channelList = dataOut.channelList
921 else:
873 else:
922 channelIndexList = []
874 channelIndexList = []
923 for channel in channelList:
875 for channel in channelList:
924 if channel not in dataOut.channelList:
876 if channel not in dataOut.channelList:
925 raise ValueError, "Channel %d is not in dataOut.channelList"
877 raise ValueError, "Channel %d is not in dataOut.channelList"
926 channelIndexList.append(dataOut.channelList.index(channel))
878 channelIndexList.append(dataOut.channelList.index(channel))
927
879
928 try:
880 try:
929 factor = dataOut.normFactor
881 factor = dataOut.normFactor
930 except:
882 except:
931 factor = 1
883 factor = 1
932
884
933 y = dataOut.getHeiRange()
885 y = dataOut.getHeiRange()
934
886
935 #for voltage
887 #for voltage
936 if dataOut.type == 'Voltage':
888 if dataOut.type == 'Voltage':
937 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
889 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
938 x = x.real
890 x = x.real
939 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
891 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
940
892
941 #for spectra
893 #for spectra
942 if dataOut.type == 'Spectra':
894 if dataOut.type == 'Spectra':
943 x = dataOut.data_spc[channelIndexList,:,:]/factor
895 x = dataOut.data_spc[channelIndexList,:,:]/factor
944 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
896 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
945 x = numpy.average(x, axis=1)
897 x = numpy.average(x, axis=1)
946
898
947
899
948 xdB = 10*numpy.log10(x)
900 xdB = 10*numpy.log10(x)
949
901
950 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
902 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
951 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
903 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
952 xlabel = "dB"
904 xlabel = "dB"
953 ylabel = "Range (Km)"
905 ylabel = "Range (Km)"
954
906
955 if not self.isConfig:
907 if not self.isConfig:
956
908
957 nplots = 1
909 nplots = 1
958
910
959 self.setup(id=id,
911 self.setup(id=id,
960 nplots=nplots,
912 nplots=nplots,
961 wintitle=wintitle,
913 wintitle=wintitle,
962 show=show)
914 show=show)
963
915
964 if ymin == None: ymin = numpy.nanmin(y)
916 if ymin == None: ymin = numpy.nanmin(y)
965 if ymax == None: ymax = numpy.nanmax(y)
917 if ymax == None: ymax = numpy.nanmax(y)
966 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
918 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
967 if xmax == None: xmax = numpy.nanmax(xdB)*0.9
919 if xmax == None: xmax = numpy.nanmax(xdB)*0.9
968
920
969 self.__isConfig = True
921 self.__isConfig = True
970
922
971 self.setWinTitle(title)
923 self.setWinTitle(title)
972
924
973 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
925 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
974 axes = self.axesList[0]
926 axes = self.axesList[0]
975
927
976 legendlabels = ["channel %d"%x for x in channelList]
928 legendlabels = ["channel %d"%x for x in channelList]
977 axes.pmultiline(xdB, y,
929 axes.pmultiline(xdB, y,
978 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
930 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
979 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
931 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
980 ytick_visible=True, nxticks=5,
932 ytick_visible=True, nxticks=5,
981 grid='x')
933 grid='x')
982
934
983 self.draw()
935 self.draw()
984
936
985 if save:
937 if save:
986 date = thisDatetime.strftime("%Y%m%d")
938 date = thisDatetime.strftime("%Y%m%d")
987 if figfile == None:
939 if figfile == None:
988 figfile = self.getFilename(name = date)
940 figfile = self.getFilename(name = date)
989
941
990 self.saveFigure(figpath, figfile)
942 self.saveFigure(figpath, figfile)
991
943
992 self.counter_imagwr += 1
944 self.counter_imagwr += 1
993 if (ftp and (self.counter_imagwr==wr_period)):
945 if (ftp and (self.counter_imagwr==wr_period)):
994 ftp_filename = os.path.join(figpath,figfile)
946 ftp_filename = os.path.join(figpath,figfile)
995 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
947 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
996 self.counter_imagwr = 0
948 self.counter_imagwr = 0
997
949
998 class Noise(Figure):
950 class Noise(Figure):
999
951
1000 isConfig = None
952 isConfig = None
1001 __nsubplots = None
953 __nsubplots = None
1002
954
1003 PREFIX = 'noise'
955 PREFIX = 'noise'
1004
956
1005 def __init__(self):
957 def __init__(self):
1006
958
1007 self.timerange = 24*60*60
959 self.timerange = 24*60*60
1008 self.isConfig = False
960 self.isConfig = False
1009 self.__nsubplots = 1
961 self.__nsubplots = 1
1010 self.counter_imagwr = 0
962 self.counter_imagwr = 0
1011 self.WIDTH = 600
963 self.WIDTH = 600
1012 self.HEIGHT = 300
964 self.HEIGHT = 300
1013 self.WIDTHPROF = 120
965 self.WIDTHPROF = 120
1014 self.HEIGHTPROF = 0
966 self.HEIGHTPROF = 0
1015 self.xdata = None
967 self.xdata = None
1016 self.ydata = None
968 self.ydata = None
1017
969
1018 self.PLOT_CODE = 77
970 self.PLOT_CODE = 77
1019 self.FTP_WEI = None
971 self.FTP_WEI = None
1020 self.EXP_CODE = None
972 self.EXP_CODE = None
1021 self.SUB_EXP_CODE = None
973 self.SUB_EXP_CODE = None
1022 self.PLOT_POS = None
974 self.PLOT_POS = None
1023
975
1024 def getSubplots(self):
976 def getSubplots(self):
1025
977
1026 ncol = 1
978 ncol = 1
1027 nrow = 1
979 nrow = 1
1028
980
1029 return nrow, ncol
981 return nrow, ncol
1030
982
1031 def openfile(self, filename):
983 def openfile(self, filename):
1032 f = open(filename,'w+')
984 f = open(filename,'w+')
1033 f.write('\n\n')
985 f.write('\n\n')
1034 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
986 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
1035 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
987 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
1036 f.close()
988 f.close()
1037
989
1038 def save_data(self, filename_phase, data, data_datetime):
990 def save_data(self, filename_phase, data, data_datetime):
1039 f=open(filename_phase,'a')
991 f=open(filename_phase,'a')
1040 timetuple_data = data_datetime.timetuple()
992 timetuple_data = data_datetime.timetuple()
1041 day = str(timetuple_data.tm_mday)
993 day = str(timetuple_data.tm_mday)
1042 month = str(timetuple_data.tm_mon)
994 month = str(timetuple_data.tm_mon)
1043 year = str(timetuple_data.tm_year)
995 year = str(timetuple_data.tm_year)
1044 hour = str(timetuple_data.tm_hour)
996 hour = str(timetuple_data.tm_hour)
1045 minute = str(timetuple_data.tm_min)
997 minute = str(timetuple_data.tm_min)
1046 second = str(timetuple_data.tm_sec)
998 second = str(timetuple_data.tm_sec)
1047 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
999 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1048 f.close()
1000 f.close()
1049
1001
1050
1002
1051 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1003 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1052
1004
1053 self.__showprofile = showprofile
1005 self.__showprofile = showprofile
1054 self.nplots = nplots
1006 self.nplots = nplots
1055
1007
1056 ncolspan = 7
1008 ncolspan = 7
1057 colspan = 6
1009 colspan = 6
1058 self.__nsubplots = 2
1010 self.__nsubplots = 2
1059
1011
1060 self.createFigure(id = id,
1012 self.createFigure(id = id,
1061 wintitle = wintitle,
1013 wintitle = wintitle,
1062 widthplot = self.WIDTH+self.WIDTHPROF,
1014 widthplot = self.WIDTH+self.WIDTHPROF,
1063 heightplot = self.HEIGHT+self.HEIGHTPROF,
1015 heightplot = self.HEIGHT+self.HEIGHTPROF,
1064 show=show)
1016 show=show)
1065
1017
1066 nrow, ncol = self.getSubplots()
1018 nrow, ncol = self.getSubplots()
1067
1019
1068 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1020 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1069
1021
1070
1022
1071 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1023 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1072 xmin=None, xmax=None, ymin=None, ymax=None,
1024 xmin=None, xmax=None, ymin=None, ymax=None,
1073 timerange=None,
1025 timerange=None,
1074 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1026 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1075 server=None, folder=None, username=None, password=None,
1027 server=None, folder=None, username=None, password=None,
1076 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1028 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1077
1029
1078 if channelList == None:
1030 if channelList == None:
1079 channelIndexList = dataOut.channelIndexList
1031 channelIndexList = dataOut.channelIndexList
1080 channelList = dataOut.channelList
1032 channelList = dataOut.channelList
1081 else:
1033 else:
1082 channelIndexList = []
1034 channelIndexList = []
1083 for channel in channelList:
1035 for channel in channelList:
1084 if channel not in dataOut.channelList:
1036 if channel not in dataOut.channelList:
1085 raise ValueError, "Channel %d is not in dataOut.channelList"
1037 raise ValueError, "Channel %d is not in dataOut.channelList"
1086 channelIndexList.append(dataOut.channelList.index(channel))
1038 channelIndexList.append(dataOut.channelList.index(channel))
1087
1039
1088 if timerange != None:
1040 if timerange != None:
1089 self.timerange = timerange
1041 self.timerange = timerange
1090
1042
1091 tmin = None
1043 tmin = None
1092 tmax = None
1044 tmax = None
1093 x = dataOut.getTimeRange()
1045 x = dataOut.getTimeRange()
1094 y = dataOut.getHeiRange()
1046 y = dataOut.getHeiRange()
1095 factor = dataOut.normFactor
1047 factor = dataOut.normFactor
1096 noise = dataOut.noise()/factor
1048 noise = dataOut.noise()/factor
1097 noisedB = 10*numpy.log10(noise)
1049 noisedB = 10*numpy.log10(noise)
1098
1050
1099 #thisDatetime = dataOut.datatime
1051 #thisDatetime = dataOut.datatime
1100 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1052 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1101 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1053 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1102 xlabel = ""
1054 xlabel = ""
1103 ylabel = "Intensity (dB)"
1055 ylabel = "Intensity (dB)"
1104
1056
1105 if not self.isConfig:
1057 if not self.isConfig:
1106
1058
1107 nplots = 1
1059 nplots = 1
1108
1060
1109 self.setup(id=id,
1061 self.setup(id=id,
1110 nplots=nplots,
1062 nplots=nplots,
1111 wintitle=wintitle,
1063 wintitle=wintitle,
1112 showprofile=showprofile,
1064 showprofile=showprofile,
1113 show=show)
1065 show=show)
1114
1066
1115 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1067 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1116 if ymin == None: ymin = numpy.nanmin(noisedB) - 10.0
1068 if ymin == None: ymin = numpy.nanmin(noisedB) - 10.0
1117 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1069 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1118
1070
1119 self.FTP_WEI = ftp_wei
1071 self.FTP_WEI = ftp_wei
1120 self.EXP_CODE = exp_code
1072 self.EXP_CODE = exp_code
1121 self.SUB_EXP_CODE = sub_exp_code
1073 self.SUB_EXP_CODE = sub_exp_code
1122 self.PLOT_POS = plot_pos
1074 self.PLOT_POS = plot_pos
1123
1075
1124
1076
1125 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1077 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1126 self.isConfig = True
1078 self.isConfig = True
1127
1079
1128 self.xdata = numpy.array([])
1080 self.xdata = numpy.array([])
1129 self.ydata = numpy.array([])
1081 self.ydata = numpy.array([])
1130
1082
1131 #open file beacon phase
1083 #open file beacon phase
1132 path = '%s%03d' %(self.PREFIX, self.id)
1084 path = '%s%03d' %(self.PREFIX, self.id)
1133 noise_file = os.path.join(path,'%s.txt'%self.name)
1085 noise_file = os.path.join(path,'%s.txt'%self.name)
1134 self.filename_noise = os.path.join(figpath,noise_file)
1086 self.filename_noise = os.path.join(figpath,noise_file)
1135 self.openfile(self.filename_noise)
1087 self.openfile(self.filename_noise)
1136
1088
1137
1089
1138 #store data beacon phase
1090 #store data beacon phase
1139 self.save_data(self.filename_noise, noisedB, thisDatetime)
1091 self.save_data(self.filename_noise, noisedB, thisDatetime)
1140
1092
1141
1093
1142 self.setWinTitle(title)
1094 self.setWinTitle(title)
1143
1095
1144
1096
1145 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1097 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1146
1098
1147 legendlabels = ["channel %d"%(idchannel+1) for idchannel in channelList]
1099 legendlabels = ["channel %d"%(idchannel+1) for idchannel in channelList]
1148 axes = self.axesList[0]
1100 axes = self.axesList[0]
1149
1101
1150 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1102 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1151
1103
1152 if len(self.ydata)==0:
1104 if len(self.ydata)==0:
1153 self.ydata = noisedB[channelIndexList].reshape(-1,1)
1105 self.ydata = noisedB[channelIndexList].reshape(-1,1)
1154 else:
1106 else:
1155 self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1)))
1107 self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1)))
1156
1108
1157
1109
1158 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1110 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1159 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1111 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1160 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1112 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1161 XAxisAsTime=True, grid='both'
1113 XAxisAsTime=True, grid='both'
1162 )
1114 )
1163
1115
1164 self.draw()
1116 self.draw()
1165
1117
1166 # if save:
1118 # if save:
1167 #
1119 #
1168 # if figfile == None:
1120 # if figfile == None:
1169 # figfile = self.getFilename(name = self.name)
1121 # figfile = self.getFilename(name = self.name)
1170 #
1122 #
1171 # self.saveFigure(figpath, figfile)
1123 # self.saveFigure(figpath, figfile)
1172
1124
1173 if save:
1125 if save:
1174
1126
1175 self.counter_imagwr += 1
1127 self.counter_imagwr += 1
1176 if (self.counter_imagwr==wr_period):
1128 if (self.counter_imagwr==wr_period):
1177 if figfile == None:
1129 if figfile == None:
1178 figfile = self.getFilename(name = self.name)
1130 figfile = self.getFilename(name = self.name)
1179 self.saveFigure(figpath, figfile)
1131 self.saveFigure(figpath, figfile)
1180
1132
1181 if ftp:
1133 if ftp:
1182 #provisionalmente envia archivos en el formato de la web en tiempo real
1134 #provisionalmente envia archivos en el formato de la web en tiempo real
1183 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1135 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1184 path = '%s%03d' %(self.PREFIX, self.id)
1136 path = '%s%03d' %(self.PREFIX, self.id)
1185 ftp_file = os.path.join(path,'ftp','%s.png'%name)
1137 ftp_file = os.path.join(path,'ftp','%s.png'%name)
1186 self.saveFigure(figpath, ftp_file)
1138 self.saveFigure(figpath, ftp_file)
1187 ftp_filename = os.path.join(figpath,ftp_file)
1139 ftp_filename = os.path.join(figpath,ftp_file)
1188 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1140 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1189 self.counter_imagwr = 0
1141 self.counter_imagwr = 0
1190
1142
1191 self.counter_imagwr = 0
1143 self.counter_imagwr = 0
1192
1144
1193 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1145 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1194 self.isConfig = False
1146 self.isConfig = False
1195 del self.xdata
1147 del self.xdata
1196 del self.ydata
1148 del self.ydata
@@ -1,121 +1,117
1 import os, sys
1 import os, sys
2
2
3 path = os.path.split(os.getcwd())[0]
3 path = os.path.split(os.getcwd())[0]
4 sys.path.append(path)
4 sys.path.append(path)
5
5
6 from controller import *
6 from controller import *
7
7
8 desc = "EWDrifts Experiment Test"
8 desc = "EWDrifts Experiment Test"
9 filename = "ewdrifts2.xml"
9 filename = "ewdrifts2.xml"
10
10
11 controllerObj = Project()
11 controllerObj = Project()
12
12
13 controllerObj.setup(id = '191', name='test01', description=desc)
13 controllerObj.setup(id = '191', name='test01', description=desc)
14
14
15 path='/remote/ewdrifts/RAW_EXP/EW_DRIFT_FARADAY/EW_Drift'
15 path='/remote/ewdrifts/RAW_EXP/EW_DRIFT_FARADAY/EW_Drift'
16
16
17 path = '/Users/dsuarez/Documents/Radar/drifts'
17
18 path = '/Users/dsuarez/Documents/EW_DRIFT_WITH_TR'
18 path = '/home/signalchain/Puma/2014_07/EW_Drift'
19 path = '/home/administrator/Radar/drifts/2014'
19
20 readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage',
20 readUnitConfObj = controllerObj.addReadUnit(datatype='VoltageReader',
21 path=path,
21 path=path,
22 startDate='2014/01/11',
22 startDate='2014/07/01',
23 endDate='2014/12/12',
23 endDate='2014/07/30',
24 startTime='00:00:00',
24 startTime='00:00:00',
25 endTime='23:59:59',
25 endTime='23:59:59',
26 online=0,
26 online=0,
27 delay=5,
27 delay=5,
28 walk=0)
28 walk=0)
29
29
30 procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId())
30 opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock')
31
31
32 opObj11 = procUnitConfObj0.addOperation(name='Scope', optype='other')
32 procUnitConfObj0 = controllerObj.addProcUnit(datatype='VoltageProc', inputId=readUnitConfObj.getId())
33 opObj11.addParameter(name='id', value='101', format='int')
34 opObj11.addParameter(name='wintitle', value='AMISR', format='str')
35
33
36 #
34 opObj11 = procUnitConfObj0.addOperation(name='ProfileSelector', optype='other')
37 # opObj11 = procUnitConfObj0.addOperation(name='ProfileSelector', optype='other')
35 opObj11.addParameter(name='profileRangeList', value='0,127', format='intlist')
38 # opObj11.addParameter(name='profileRangeList', value='0,127', format='intlist')
36
39 #
37 opObj11 = procUnitConfObj0.addOperation(name='filterByHeights')
40 # opObj11 = procUnitConfObj0.addOperation(name='filterByHeights')
38 opObj11.addParameter(name='window', value='3', format='int')
41 # opObj11.addParameter(name='window', value='3', format='int')
39
42 #
40 opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other')
43 # opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other')
41
44 #
42 procUnitConfObj1 = controllerObj.addProcUnit(datatype='SpectraProc', inputId=procUnitConfObj0.getId())
45 #
43 procUnitConfObj1.addParameter(name='nFFTPoints', value='128', format='int')
46 # procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId())
44 procUnitConfObj1.addParameter(name='nProfiles', value='128', format='int')
47 # procUnitConfObj1.addParameter(name='nFFTPoints', value='128', format='int')
45
48 # procUnitConfObj1.addParameter(name='nProfiles', value='128', format='int')
46
49 #
47 opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
50 #
48 opObj11.addParameter(name='timeInterval', value='60', format='float')
51 # opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
49
52 # opObj11.addParameter(name='timeInterval', value='60', format='float')
50 opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
53 #
51 opObj11.addParameter(name='id', value='100', format='int')
54 # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
52 opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str')
55 # opObj11.addParameter(name='id', value='100', format='int')
56 # opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str')
57 # #opObj11.addParameter(name='channelList', value='0,1,2,3', format='intlist')
53 # #opObj11.addParameter(name='channelList', value='0,1,2,3', format='intlist')
58 # # opObj11.addParameter(name='zmin', value='0', format='int')
54 # # opObj11.addParameter(name='zmin', value='0', format='int')
59 # # opObj11.addParameter(name='zmax', value='100', format='int')
55 # # opObj11.addParameter(name='zmax', value='100', format='int')
60 # opObj11.addParameter(name='showprofile', value='0', format='int')
56 # opObj11.addParameter(name='showprofile', value='0', format='int')
61 # opObj11.addParameter(name='save', value='1', format='bool')
57 # opObj11.addParameter(name='save', value='1', format='bool')
62 # opObj11.addParameter(name='figpath', value='/Users/dsuarez/Pictures/tr', format='str')
58 # opObj11.addParameter(name='figpath', value='/Users/dsuarez/Pictures/tr', format='str')
63 #
59 #
64 #
60 #
65 # opObj11 = procUnitConfObj1.addOperation(name='Noise', optype='other')
61 # opObj11 = procUnitConfObj1.addOperation(name='Noise', optype='other')
66 # opObj11.addParameter(name='id', value='101', format='int')
62 # opObj11.addParameter(name='id', value='101', format='int')
67 # opObj11.addParameter(name='wintitle', value='TR800KW', format='str')
63 # opObj11.addParameter(name='wintitle', value='TR800KW', format='str')
68 # opObj11.addParameter(name='xmin', value='10', format='float')
64 # opObj11.addParameter(name='xmin', value='10', format='float')
69 # opObj11.addParameter(name='xmax', value='11.5', format='float')
65 # opObj11.addParameter(name='xmax', value='11.5', format='float')
70 # opObj11.addParameter(name='ymin', value='55', format='float')
66 # opObj11.addParameter(name='ymin', value='55', format='float')
71 # opObj11.addParameter(name='ymax', value='65', format='float')
67 # opObj11.addParameter(name='ymax', value='65', format='float')
72 # opObj11.addParameter(name='save', value='1', format='bool')
68 # opObj11.addParameter(name='save', value='1', format='bool')
73 # opObj11.addParameter(name='figpath', value='/Users/dsuarez/Pictures/tr', format='str')
69 # opObj11.addParameter(name='figpath', value='/Users/dsuarez/Pictures/tr', format='str')
74
70
75 #
71 #
76 #opObj11 = procUnitConfObj1.addOperation(name='PowerProfilePlot', optype='other')
72 #opObj11 = procUnitConfObj1.addOperation(name='PowerProfilePlot', optype='other')
77 #opObj11.addParameter(name='idfigure', value='2', format='int')
73 #opObj11.addParameter(name='id', value='2', format='int')
78 #opObj11.addParameter(name='channelList', value='0,1,2,3', format='intlist')
74 #opObj11.addParameter(name='channelList', value='0,1,2,3', format='intlist')
79 #opObj11.addParameter(name='save', value='1', format='bool')
75 #opObj11.addParameter(name='save', value='1', format='bool')
80 #opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/EW_DRIFTS_2012_DEC', format='str')
76 #opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/EW_DRIFTS_2012_DEC', format='str')
81 ##opObj11.addParameter(name='xmin', value='10', format='int')
77 ##opObj11.addParameter(name='xmin', value='10', format='int')
82 ##opObj11.addParameter(name='xmax', value='40', format='int')
78 ##opObj11.addParameter(name='xmax', value='40', format='int')
83 #
79 #
84 # opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='other')
80 # opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='other')
85 # opObj11.addParameter(name='idfigure', value='3', format='int')
81 # opObj11.addParameter(name='id', value='3', format='int')
86 # opObj11.addParameter(name='wintitle', value='CrossSpectraPlot', format='str')
82 # opObj11.addParameter(name='wintitle', value='CrossSpectraPlot', format='str')
87 # #opObj11.addParameter(name='save', value='1', format='bool')
83 # #opObj11.addParameter(name='save', value='1', format='bool')
88 # #opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/EW_DRIFTS_2012_DEC', format='str')
84 # #opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/EW_DRIFTS_2012_DEC', format='str')
89 # ##opObj11.addParameter(name='zmin', value='10', format='int')
85 # ##opObj11.addParameter(name='zmin', value='10', format='int')
90 # ##opObj11.addParameter(name='zmax', value='40', format='int')
86 # ##opObj11.addParameter(name='zmax', value='40', format='int')
91 # ##opObj11.addParameter(name='save', value='1', format='bool')
87 # ##opObj11.addParameter(name='save', value='1', format='bool')
92 # ##opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/cross_spc', format='str')
88 # ##opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/cross_spc', format='str')
93 # opObj11.addParameter(name='zmin', value='20', format='int')
89 # opObj11.addParameter(name='zmin', value='20', format='int')
94 # opObj11.addParameter(name='zmax', value='40', format='int')
90 # opObj11.addParameter(name='zmax', value='40', format='int')
95 # opObj11.addParameter(name='save', value='1', format='bool')
91 # opObj11.addParameter(name='save', value='1', format='bool')
96 # opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/ew_drifts_mz', format='str')
92 # opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/ew_drifts_mz', format='str')
97 #
93 #
98 # #
94 # #
99 # opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
95 # opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
100 # opObj11.addParameter(name='id', value='102', format='int')
96 # opObj11.addParameter(name='id', value='102', format='int')
101 # opObj11.addParameter(name='wintitle', value='RTIPLot', format='str')
97 # opObj11.addParameter(name='wintitle', value='RTIPLot', format='str')
102 # opObj11.addParameter(name='xmin', value='10', format='float')
98 # opObj11.addParameter(name='xmin', value='10', format='float')
103 # opObj11.addParameter(name='xmax', value='11.5', format='float')
99 # opObj11.addParameter(name='xmax', value='11.5', format='float')
104 # # opObj11.addParameter(name='zmin', value='20', format='int')
100 # # opObj11.addParameter(name='zmin', value='20', format='int')
105 # # opObj11.addParameter(name='zmax', value='40', format='int')
101 # # opObj11.addParameter(name='zmax', value='40', format='int')
106 # # #opObj11.addParameter(name='channelList', value='0,1,2,3', format='intlist')
102 # # #opObj11.addParameter(name='channelList', value='0,1,2,3', format='intlist')
107 # # #opObj11.addParameter(name='timerange', value='86400', format='int')
103 # # #opObj11.addParameter(name='timerange', value='86400', format='int')
108 # opObj11.addParameter(name='showprofile', value='0', format='int')
104 # opObj11.addParameter(name='showprofile', value='0', format='int')
109 # opObj11.addParameter(name='save', value='1', format='bool')
105 # opObj11.addParameter(name='save', value='1', format='bool')
110 # opObj11.addParameter(name='figpath', value='/Users/dsuarez/Pictures/tr', format='str')
106 # opObj11.addParameter(name='figpath', value='/Users/dsuarez/Pictures/tr', format='str')
111
107
112 print "Escribiendo el archivo XML"
108 print "Escribiendo el archivo XML"
113 controllerObj.writeXml(filename)
109 controllerObj.writeXml(filename)
114 print "Leyendo el archivo XML"
110 print "Leyendo el archivo XML"
115 controllerObj.readXml(filename)
111 controllerObj.readXml(filename)
116
112
117 controllerObj.createObjects()
113 controllerObj.createObjects()
118 controllerObj.connectObjects()
114 controllerObj.connectObjects()
119 controllerObj.run()
115 controllerObj.run()
120
116
121
117
@@ -1,97 +1,79
1 import os, sys
1 import os, sys
2
2
3 path = os.path.split(os.getcwd())[0]
3 path = os.path.split(os.getcwd())[0]
4 sys.path.append(path)
4 sys.path.append(path)
5
5
6 from controller import *
6 from controller import *
7
7
8 desc = "EWDrifts+Imaging+Faraday Experiments"
8 desc = "EWDrifts+Imaging+Faraday Experiments"
9 filename = "imaging_plots.xml"
9 filename = "imaging_plots.xml"
10
10
11 controllerObj = Project()
11 controllerObj = Project()
12
12
13 controllerObj.setup(id = '191', name='test01', description=desc)
13 controllerObj.setup(id = '191', name='test01', description=desc)
14
14
15 path = '/home/dsuarez/EW_Faraday_imaging'
15 path = '/media/signalchain/datos/IMAGING/IMAGING/setiembre2014'
16 path = '/media/datos/IMAGING/IMAGING/abril2014'
17
16
18 readUnitConfObj = controllerObj.addReadUnit(datatype='Spectra',
17 readUnitConfObj = controllerObj.addReadUnit(datatype='SpectraReader',
19 path=path,
18 path=path,
20 startDate='2013/09/27',
19 startDate='2014/09/22',
21 endDate='2013/09/27',
20 endDate='2014/09/22',
22 startTime='19:00:00',
21 startTime='00:30:00',
23 endTime='23:59:59',
22 endTime='23:59:59',
24 delay=2,
23 delay=5,
25 online=1,
24 online=0,
26 walk=1)
25 walk=1)
27
26
28 opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock')
27 opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock')
29
28
30 ######################## IMAGING #############################################
29 ######################## IMAGING #############################################
31
30
32 procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId())
31 procUnitConfObj1 = controllerObj.addProcUnit(datatype='SpectraProc', inputId=readUnitConfObj.getId())
33
34
35 # opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
36 # opObj11.addParameter(name='n', value='2', format='float')
37
32
38 opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
33 opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
39 opObj11.addParameter(name='id', value='2000', format='int')
34 opObj11.addParameter(name='id', value='2000', format='int')
40 opObj11.addParameter(name='wintitle', value='Imaging', format='str')
35 opObj11.addParameter(name='wintitle', value='Imaging', format='str')
41 # opObj11.addParameter(name='zmin', value='35', format='int')
36 opObj11.addParameter(name='zmin', value='15', format='int')
42 # opObj11.addParameter(name='zmax', value='45', format='int')
37 opObj11.addParameter(name='zmax', value='45', format='int')
43 # opObj11.addParameter(name='ymin', value='0', format='int')
38 opObj11.addParameter(name='figpath', value='/home/signalchain/Pictures/imaging', format='str')
44 # opObj11.addParameter(name='ymax', value='300', format='int')
45 opObj11.addParameter(name='save', value='1', format='int')
46 opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/imaging_abril2014', format='str')
47 opObj11.addParameter(name='wr_period', value='5', format='int')
48 opObj11.addParameter(name='ftp', value='1', format='int')
49 opObj11.addParameter(name='server', value='jro-app.igp.gob.pe', format='str')
50 opObj11.addParameter(name='folder', value='/home/wmaster/graficos', format='str')
51 opObj11.addParameter(name='username', value='wmaster', format='str')
52 opObj11.addParameter(name='password', value='mst2010vhf', format='str')
53 opObj11.addParameter(name='ftp_wei', value='0', format='int')
54 opObj11.addParameter(name='exp_code', value='13', format='int')
39 opObj11.addParameter(name='exp_code', value='13', format='int')
55 opObj11.addParameter(name='sub_exp_code', value='0', format='int')
40
56 opObj11.addParameter(name='plot_pos', value='0', format='int')
41 opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
57
42 opObj11.addParameter(name='id', value='3001', format='int')
58 # opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
43 opObj11.addParameter(name='wintitle', value='Imaging', format='str')
59 # opObj11.addParameter(name='id', value='101', format='int')
44 opObj11.addParameter(name='xmin', value='20.5', format='float')
60 # opObj11.addParameter(name='wintitle', value='Imaging', format='str')
45 opObj11.addParameter(name='xmax', value='24', format='float')
61 # opObj11.addParameter(name='xmin', value='19', format='float')
46 opObj11.addParameter(name='zmin', value='15', format='int')
62 # opObj11.addParameter(name='xmax', value='24', format='float')
47 opObj11.addParameter(name='zmax', value='45', format='int')
63 # opObj11.addParameter(name='save', value='1', format='int')
48 opObj11.addParameter(name='channelList', value='0,1,2,3', format='intlist')
64 # # opObj11.addParameter(name='figfile', value='rti-imaging.png', format='str')
49 opObj11.addParameter(name='showprofile', value='0', format='int')
65 # opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/imaging_last_night', format='str')
50 opObj11.addParameter(name='figpath', value='/home/signalchain/Pictures/imaging', format='str')
66 # opObj11.addParameter(name='ftp', value='1', format='int')
51 opObj11.addParameter(name='exp_code', value='13', format='int')
67 # opObj11.addParameter(name='ftpratio', value='3', format='int')
52
68
69
70 opObj11 = procUnitConfObj1.addOperation(name='CoherenceMap', optype='other')
53 opObj11 = procUnitConfObj1.addOperation(name='CoherenceMap', optype='other')
71 opObj11.addParameter(name='id', value='2001', format='int')
54 opObj11.addParameter(name='id', value='2001', format='int')
72 opObj11.addParameter(name='wintitle', value='Imaging', format='str')
55 opObj11.addParameter(name='wintitle', value='Imaging', format='str')
73 opObj11.addParameter(name='xmin', value='17', format='float')
56 opObj11.addParameter(name='xmin', value='20.5', format='float')
74 opObj11.addParameter(name='xmax', value='24', format='float')
57 opObj11.addParameter(name='xmax', value='24', format='float')
75 opObj11.addParameter(name='save', value='1', format='int')
58 opObj11.addParameter(name='figpath', value='/home/signalchain/Pictures/imaging', format='str')
76 opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/imaging_abril2014', format='str')
59 opObj11.addParameter(name='exp_code', value='13', format='int')
77 opObj11.addParameter(name='wr_period', value='5', format='int')
60
78 opObj11.addParameter(name='ftp', value='1', format='int')
61 opObj11 = procUnitConfObj1.addOperation(name='SendByFTP', optype='other')
62 opObj11.addParameter(name='ext', value='*.png', format='str')
63 opObj11.addParameter(name='localfolder', value='/home/signalchain/Pictures/imaging', format='str')
64 opObj11.addParameter(name='remotefolder', value='/home/wmaster/graficos', format='str')
79 opObj11.addParameter(name='server', value='jro-app.igp.gob.pe', format='str')
65 opObj11.addParameter(name='server', value='jro-app.igp.gob.pe', format='str')
80 opObj11.addParameter(name='folder', value='/home/wmaster/graficos', format='str')
81 opObj11.addParameter(name='username', value='wmaster', format='str')
66 opObj11.addParameter(name='username', value='wmaster', format='str')
82 opObj11.addParameter(name='password', value='mst2010vhf', format='str')
67 opObj11.addParameter(name='password', value='mst2010vhf', format='str')
83 opObj11.addParameter(name='ftp_wei', value='0', format='int')
68
84 opObj11.addParameter(name='exp_code', value='13', format='int')
85 opObj11.addParameter(name='sub_exp_code', value='0', format='int')
86 opObj11.addParameter(name='plot_pos', value='0', format='int')
87
69
88 print "Escribiendo el archivo XML"
70 print "Escribiendo el archivo XML"
89 controllerObj.writeXml(filename)
71 controllerObj.writeXml(filename)
90 print "Leyendo el archivo XML"
72 print "Leyendo el archivo XML"
91 controllerObj.readXml(filename)
73 controllerObj.readXml(filename)
92
74
93 controllerObj.createObjects()
75 controllerObj.createObjects()
94 controllerObj.connectObjects()
76 controllerObj.connectObjects()
95 controllerObj.run()
77 controllerObj.run()
96
78
97
79
@@ -1,82 +1,71
1 import os, sys
1 import os, sys
2
2
3 path = os.path.split(os.getcwd())[0]
3 path = os.path.split(os.getcwd())[0]
4 sys.path.append(path)
4 sys.path.append(path)
5
5
6 from controller import *
6 from controller import *
7
7
8 desc = "EWDrifts+Imaging+Faraday Experiment"
8 desc = "EWDrifts+Imaging+Faraday Experiment"
9 filename = "imaging_proc.xml"
9 filename = "imaging_proc.xml"
10
10
11 controllerObj = Project()
11 controllerObj = Project()
12
12
13 controllerObj.setup(id = '191', name='test01', description=desc)
13 controllerObj.setup(id = '191', name='test01', description=desc)
14
14
15 path = '/remote'
15 path = '/home/signalchain/Documents/remote_data/EW_Faraday_imaging'
16 path = '/home/dsuarez/.gvfs/data on 10.10.20.13/EW_Faraday_imaging/d2013270'
17 path = '/home/dsuarez/.gvfs/data on 10.10.20.13/EW_Faraday_imaging'
18
16
19 readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage',
17 readUnitConfObj = controllerObj.addReadUnit(datatype='VoltageReader',
20 path=path,
18 path=path,
21 startDate='2014/04/21',
19 startDate='2014/09/21',
22 endDate='2014/04/30',
20 endDate='2014/09/30',
23 startTime='16:00:00',
21 startTime='16:00:00',
24 endTime='23:59:59',
22 endTime='23:59:59',
25 delay=5,
23 delay=5,
26 online=1,
24 online=1,
27 walk=1)
25 walk=1)
28
26
29 opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock')
27 opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock')
30
28
31 ######################## IMAGING #############################################
29 ######################## IMAGING #############################################
32 procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId())
30 procUnitConfObj0 = controllerObj.addProcUnit(datatype='VoltageProc', inputId=readUnitConfObj.getId())
33 #
31 #
34 opObj11 = procUnitConfObj0.addOperation(name='ProfileSelector', optype='other')
32 opObj11 = procUnitConfObj0.addOperation(name='ProfileSelector', optype='other')
35 opObj11.addParameter(name='profileRangeList', value='0,39', format='intlist')
33 opObj11.addParameter(name='profileRangeList', value='0,39', format='intlist')
36 # opObj11.addParameter(name='profileRangeList', value='40,167', format='intlist')
34 # opObj11.addParameter(name='profileRangeList', value='40,167', format='intlist')
37
35
38 # opObj11 = procUnitConfObj0.addOperation(name='filterByHeights')
39 # opObj11.addParameter(name='window', value='4', format='int')
40
36
41 opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other')
37 opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other')
42 # opObj11.addParameter(name='code', value='1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,1,0,0', format='floatlist')
38 # opObj11.addParameter(name='code', value='1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,1,0,0', format='floatlist')
43 # opObj11.addParameter(name='nCode', value='2', format='int')
39 # opObj11.addParameter(name='nCode', value='2', format='int')
44 # opObj11.addParameter(name='nBaud', value='9', format='int')
40 # opObj11.addParameter(name='nBaud', value='9', format='int')
45
41
46 #opObj11 = procUnitConfObj0.addOperation(name='selectHeights')
42 procUnitConfObj1 = controllerObj.addProcUnit(datatype='SpectraProc', inputId=procUnitConfObj0.getId())
47 #opObj11.addParameter(name='maxHei', value='300', format='float')
48
49 #opObj11 = procUnitConfObj0.addOperation(name='selectHeights')
50 #opObj11.addParameter(name='minHei', value='300', format='float')
51 #opObj11.addParameter(name='maxHei', value='600', format='float')
52
53 procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId())
54 procUnitConfObj1.addParameter(name='nProfiles', value='40', format='int')
43 procUnitConfObj1.addParameter(name='nProfiles', value='40', format='int')
55 procUnitConfObj1.addParameter(name='nFFTPoints', value='40', format='int')
44 procUnitConfObj1.addParameter(name='nFFTPoints', value='40', format='int')
56
45
57 procUnitConfObj1.addParameter(name='pairsList', value='(0,1),(0,2),(0,3),(0,4),(0,5),(0,6),(0,7), \
46 procUnitConfObj1.addParameter(name='pairsList', value='(0,1),(0,2),(0,3),(0,4),(0,5),(0,6),(0,7), \
58 (1,2),(1,3),(1,4),(1,5),(1,6),(1,7), \
47 (1,2),(1,3),(1,4),(1,5),(1,6),(1,7), \
59 (2,3),(2,4),(2,5),(2,6),(2,7), \
48 (2,3),(2,4),(2,5),(2,6),(2,7), \
60 (3,4),(3,5),(3,6),(3,7), \
49 (3,4),(3,5),(3,6),(3,7), \
61 (4,5),(4,6),(4,7), \
50 (4,5),(4,6),(4,7), \
62 (5,6),(5,7), \
51 (5,6),(5,7), \
63 (6,7)', \
52 (6,7)', \
64 format='pairsList')
53 format='pairsList')
65
54
66 opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
55 opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
67 opObj11.addParameter(name='timeInterval', value='5', format='float')
56 opObj11.addParameter(name='timeInterval', value='5', format='float')
68
57
69
58
70 opObj11 = procUnitConfObj1.addOperation(name='SpectraWriter', optype='other')
59 opObj11 = procUnitConfObj1.addOperation(name='SpectraWriter', optype='other')
71 opObj11.addParameter(name='path', value='/media/datos/IMAGING/IMAGING/abril2014')
60 opObj11.addParameter(name='path', value='/media/signalchain/datos/IMAGING/IMAGING/setiembre2014')
72 opObj11.addParameter(name='blocksPerFile', value='10', format='int')
61 opObj11.addParameter(name='blocksPerFile', value='10', format='int')
73
62
74
63
75 print "Escribiendo el archivo XML"
64 print "Escribiendo el archivo XML"
76 controllerObj.writeXml(filename)
65 controllerObj.writeXml(filename)
77 print "Leyendo el archivo XML"
66 print "Leyendo el archivo XML"
78 controllerObj.readXml(filename)
67 controllerObj.readXml(filename)
79
68
80 controllerObj.createObjects()
69 controllerObj.createObjects()
81 controllerObj.connectObjects()
70 controllerObj.connectObjects()
82 controllerObj.run()
71 controllerObj.run()
General Comments 0
You need to be logged in to leave comments. Login now