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